/usr/share/perl5/Net/Google/Code/Issue/Search.pm is in libnet-google-code-perl 0.19-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | package Net::Google::Code::Issue::Search;
use Any::Moose;
use Params::Validate qw(:all);
use Any::Moose 'Util::TypeConstraints';
with 'Net::Google::Code::Role::URL';
with 'Net::Google::Code::Role::Fetchable';
with 'Net::Google::Code::Role::Pageable';
with 'Net::Google::Code::Role::HTMLTree';
use Net::Google::Code::Issue;
our %CAN_MAP = (
'all' => 1,
'open' => 2,
'new' => 6,
'verify' => 7,
);
has 'project' => (
isa => 'Str',
is => 'rw',
);
has 'results' => (
isa => 'ArrayRef[Net::Google::Code::Issue]',
is => 'rw',
default => sub { [] },
);
sub updated_after {
my $self = shift;
my ( $after, $fallback_to_search ) =
validate_pos( @_, { isa => 'DateTime' },
{ optional => 1, default => 1 } );
my @results;
my $content = $self->fetch( $self->base_feeds_url . 'issueupdates/basic' );
require Net::Google::Code::AtomParser;
my $atom_parser = Net::Google::Code::AtomParser->new;
my ( $feed, $entries ) = $atom_parser->parse( $content );
if (@$entries) {
my $min_updated =
Net::Google::Code::DateTime->new_from_string( $entries->[-1]->{updated} );
if ( $min_updated < $after ) {
# yeah! we can get all the results by parsing the feed
my %seen;
for my $entry (@$entries) {
my $updated = Net::Google::Code::DateTime->new_from_string(
$entry->{updated} );
next unless $updated >= $after;
if ( $entry->{title} =~ /issue\s+(\d+)/i ) {
next if $seen{$1}++;
push @results,
Net::Google::Code::Issue->new(
project => $self->project,
id => $1,
);
}
}
$_->load for @results;
return $self->results( \@results );
}
}
return unless $fallback_to_search;
# now we have to find issues by search
if ( $self->search( load_after_search => 1, can => 'all', q => '' ) ) {
my $results = $self->results;
@$results = grep { $_->updated >= $after } @$results;
}
}
sub search {
my $self = shift;
my %args = (
limit => 999_999_999,
load_after_search => 1,
can => 2,
colspec => 'ID+Type+Status+Priority+Milestone+Owner+Summary',
@_
);
if ( $args{can} !~ /^\d$/ ) {
$args{can} = $CAN_MAP{ $args{can} };
}
my @results;
my $mech = $self->mech;
my $url = $self->base_url . 'issues/list?';
for my $type (qw/can q sort colspec/) {
next unless defined $args{$type};
$url .= $type . '=' . $args{$type} . '&';
}
$self->fetch($url);
die "Server threw an error " . $mech->response->status_line . 'when search'
unless $mech->response->is_success;
my $content = $mech->response->content;
utf8::downgrade( $content, 1 );
if ( $mech->title =~ /issue\s+(\d+)/i ) {
# get only one ticket
my $issue = Net::Google::Code::Issue->new(
project => $self->project,
id => $1,
);
@results = $issue;
}
elsif ( $mech->title =~ /issues/i ) {
# get a ticket list
my @rows = $self->rows(
html => $content,
limit => $args{limit},
);
for my $row (@rows) {
push @results,
Net::Google::Code::Issue->new(
project => $self->project,
%$row,
);
}
}
else {
warn "no idea what the content like";
return;
}
if ( $args{load_after_search} ) {
$_->load for @results;
}
$self->results( \@results );
}
no Any::Moose;
__PACKAGE__->meta->make_immutable;
1;
__END__
=head1 NAME
Net::Google::Code::Issue::Search - Issues Search API
=head1 DESCRIPTION
=head1 INTERFACE
=over 4
=item search ( can => 'all', q = 'foo', sort => '-modified', limit => 1000, load_after_search => 1 )
do the search, the results is set to $self->results,
which is an arrayref with Net::Google::Code::Issue as element.
If a "sort" argument is specified, that will be passed to google code's
issue list.
Generally, these are composed of "+" or "-" followed by a column name.
limit => Num is to limit the results number.
load_after_search => Bool is to state if we should call $issue->load after
search
return true if search is successful, false on the other hand.
=item updated_after( date_string || DateTime object )
find all the issues that have been updated or created after the date.
the issues are all loaded.
return true if success, false on the other hand
=item project
=item results
this should be called after a successful search.
returns issues as a arrayref.
=back
=head1 AUTHOR
sunnavy C<< <sunnavy@bestpractical.com> >>
=head1 LICENCE AND COPYRIGHT
Copyright 2008-2010 Best Practical Solutions.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
|