/[Frey]/trunk/lib/Frey/Collection.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Collection.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (show annotations)
Sun Jul 13 13:09:56 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 972 byte(s)
added limit and offset to collection
1 package Frey::Collection;
2 use Moose::Role;
3
4 use Data::Dump qw/dump/;
5 use Carp;
6
7 sub collection {
8 my ( $class, $args ) = @_;
9
10 croak "expect HASH not ",dump( $args ) unless ref($args) eq 'HASH';
11
12 warn "## collection args = ",dump( $args );
13
14 my $schema = $class->SchemaClass()->Schema();
15 my $select = $class->SchemaClass()->SQLFactoryClass()->new_select();
16
17 my $table = $class->collection_table;
18
19 warn "## table $table";
20
21 my $users_t = $schema->table( $table );
22
23 $select->select( $users_t )
24 ->from( $users_t )
25 # ->where( $message_t->column('message_date'), '>=',
26 # DateTime->today()->subtract( days => 7 )->strftime( '%Y-%m-%d' ) )
27 ->limit( $args->{limit} || 20, $args->{offset} || 0 )
28 ;
29
30 my $dbh = $class->_dbh($select);
31
32 my $sth = $dbh->prepare( $select->sql($dbh) );
33
34 return
35 Fey::Object::Iterator->new(
36 classes => [ $class->meta()->ClassForTable( $users_t ) ],
37 handle => $sth,
38 bind_params => [ $select->bind_params() ],
39 );
40 }
41
42 1;

  ViewVC Help
Powered by ViewVC 1.1.26