DBIx::Class::Ordered

DBIx::Class::Ordered is a Perl module that can be used to modify the position of objects in an ordered list.
Download

DBIx::Class::Ordered Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Aran Deltac
  • Publisher web site:
  • http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Ordered.pm

DBIx::Class::Ordered Tags


DBIx::Class::Ordered Description

DBIx::Class::Ordered is a Perl module that can be used to modify the position of objects in an ordered list. DBIx::Class::Ordered is a Perl module that can be used to modify the position of objects in an ordered list.SYNOPSISCreate a table for your ordered data. CREATE TABLE items ( item_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, position INTEGER NOT NULL );Optionally, add one or more columns to specify groupings, allowing you to maintain independent ordered lists within one table: CREATE TABLE items ( item_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, position INTEGER NOT NULL, group_id INTEGER NOT NULL );Or even CREATE TABLE items ( item_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, position INTEGER NOT NULL, group_id INTEGER NOT NULL, other_group_id INTEGER NOT NULL );In your Schema or DB class add "Ordered" to the top of the component list. __PACKAGE__->load_components(qw( Ordered ... ));Specify the column that stores the position number for each row. package My::Item; __PACKAGE__->position_column('position');If you are using one grouping column, specify it as follows: __PACKAGE__->grouping_column('group_id');Or if you have multiple grouping columns: __PACKAGE__->grouping_column();That's it, now you can change the position of your objects. #!/use/bin/perl use My::Item; my $item = My::Item->create({ name=>'Matt S. Trout' }); # If using grouping_column: my $item = My::Item->create({ name=>'Matt S. Trout', group_id=>1 }); my $rs = $item->siblings(); my @siblings = $item->siblings(); my $sibling; $sibling = $item->first_sibling(); $sibling = $item->last_sibling(); $sibling = $item->previous_sibling(); $sibling = $item->next_sibling(); $item->move_previous(); $item->move_next(); $item->move_first(); $item->move_last(); $item->move_to( $position ); $item->move_to_group( 'groupname' ); $item->move_to_group( 'groupname', $position ); $item->move_to_group( {group_id=>'groupname', 'other_group_id=>'othergroupname'} ); $item->move_to_group( {group_id=>'groupname', 'other_group_id=>'othergroupname'}, $position ); Requirements: · Perl


DBIx::Class::Ordered Related Software