[Bps-public-commit] r19689 - in Net-Google-Code/trunk/lib/Net/Google: . Code/Issue

sunnavy at bestpractical.com sunnavy at bestpractical.com
Fri May 15 08:29:26 EDT 2009


Author: sunnavy
Date: Fri May 15 08:29:25 2009
New Revision: 19689

Modified:
   Net-Google-Code/trunk/lib/Net/Google/Code.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm

Log:
we can limit the columns number from Pagable role now

Modified: Net-Google-Code/trunk/lib/Net/Google/Code.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code.pm	Fri May 15 08:29:25 2009
@@ -134,7 +134,7 @@
 sub load_downloads {
     my $self = shift;
     my $content = $self->fetch( $self->base_feeds_url . 'downloads/list' );
-    my @names = $self->first_columns( $content );
+    my @names = $self->first_columns( html => $content );
     my @downloads;
     require Net::Google::Code::Download;
     for my $name ( @names ) {

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm	Fri May 15 08:29:25 2009
@@ -44,12 +44,18 @@
     default => sub { [] },
 );
 
+has 'limit' => (
+    isa => 'Int',
+    is  => 'rw',
+);
+
 sub search {
     my $self = shift;
     if ( scalar @_ ) {
         my %args = @_;
         $self->_can( $args{_can} ) if defined $args{_can};
         $self->_q( $args{_q} )     if defined $args{_q};
+        $self->limit( $args{limit} ) if defined $args{limit};
     }
 
     $self->fetch( $self->base_url . 'issues/list' );
@@ -68,16 +74,20 @@
 
     if ( $mech->title =~ /Issue\s+(\d+)/ ) {
         # get only one ticket
-        my $issue = Net::Google::Code::Issue->new( id => $1 );
+        my $issue =
+          Net::Google::Code::Issue->new( project => $self->project, id => $1, );
         $self->results( [ $issue ] );
     }
     elsif ( $mech->title =~ /Issues/ ) {
 
         # get a ticket list
-        my @ids = $self->first_columns($content);
+        my @ids = $self->first_columns(html => $content, limit => $self->limit);
         my @issues;
         for my $id ( @ids ) {
-            my $issue = Net::Google::Code::Issue->new( id => $id );
+            my $issue = Net::Google::Code::Issue->new(
+                project => $self->project,
+                id      => $id,
+            );
             push @issues, $issue;
         }
         $self->results( \@issues );

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm	Fri May 15 08:29:25 2009
@@ -8,7 +8,18 @@
 
 sub first_columns {
     my $self = shift;
-    my $tree = shift;
+    my %args = validate(
+        @_,
+        {
+            html  => { type => SCALAR },
+            limit => {
+                type     => SCALAR,
+                optional => 1,
+            },
+        }
+    );
+    $args{limit} ||= 999_999_999; # the impossible huge limit
+    my $tree = $args{html};
     $tree = $self->html_tree( html => $tree ) unless blessed $tree;
 
     my @columns;
@@ -19,6 +30,7 @@
     {
         push @columns, $self->_first_columns($tree);
 
+        $total = $args{limit} if $args{limit} < $total;
         while ( scalar @columns < $total ) {
             if ( $self->mech->follow_link( text_regex => qr/Next\s+/ ) ) {
                 if ( $self->mech->response->is_success ) {
@@ -35,7 +47,13 @@
             }
         }
     }
-    return @columns;
+    if ( scalar @columns > $args{limit} ) {
+        # this happens when limit is less than the 1st page's number 
+        return @columns[0 .. $args{limit}-1];
+    }
+    else {
+        return @columns;
+    }
 }
 
 sub _first_columns {



More information about the Bps-public-commit mailing list