Code/Issue/Search.pm

filter: Statementstmt 94.5% 70 / 74 Branchbran 73.0% 19 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 90.0% 99 / 110 CC 19 SCAR 21.1
CC
19
Cov
89%
search
10.7
updated_after
10.1
BEGIN
1.0
CRAP 8.2
« Code/Role/Pageable.pm ↑ Summary Code/Download.pm »
1 package Net::Google::Code::Issue::Search;
2 2 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Any::Moose 'Util::TypeConstraints';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 with 'Net::Google::Code::Role::URL';
6 2 with 'Net::Google::Code::Role::Fetchable';
7 2 with 'Net::Google::Code::Role::Pageable';
8 2 with 'Net::Google::Code::Role::HTMLTree';
9 2 ▶use Net::Google::Code::Issue;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our %CAN_MAP = (
12 'all' => 1,
13 'open' => 2,
14 'new' => 6,
15 'verify' => 7,
16 );
17  
18  
19 2 has 'project' => (
20 isa => 'Str',
21 is => 'rw',
22 );
23  
24 has 'results' => (
25 isa => 'ArrayRef[Net::Google::Code::Issue]',
26 is => 'rw',
27 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 );
29  
30 4 ▶sub updated_after {
Subroutine updated_after: called CC=10 SCAR=23.1
Pod documented
31 4 my $self = shift;
32 4 my ( $after, $fallback_to_search ) =
33 validate_pos( @_, { isa => 'DateTime' },
34 { optional => 1, default => 1 } );
35
36 4 my @results;
37  
38 4 my $content = $self->fetch( $self->base_feeds_url . 'issueupdates/basic' );
39 4 require Net::Google::Code::AtomParser;
40 4 my $atom_parser = Net::Google::Code::AtomParser->new;
41 4 my ( $feed, $entries ) = $atom_parser->parse( $content );
42 4 ▶ if (@$entries) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$entries) 4 0 4
43 my $min_updated =
44 4 Net::Google::Code::DateTime->new_from_string( $entries->[-1]->{updated} );
45 4 ▶ if ( $min_updated < $after ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_updated < $after) 2 2 4
46  
47 # yeah! we can get all the results by parsing the feed
48 2 my %seen;
49 2 for my $entry (@$entries) {
50 my $updated = Net::Google::Code::DateTime->new_from_string(
51 40 $entry->{updated} );
52 40 ▶ next unless $updated >= $after;
Branch: 1 branch
BranchTrueFalseTotal
unless $updated >= $after 29 11 40
53 11 ▶ if ( $entry->{title} =~ /issue\s+(\d+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"title"} =~ /issue\s+(\d+)/i) 11 0 11
54 11 ▶ next if $seen{$1}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$1}++ 7 4 11
55 4 push @results,
56 Net::Google::Code::Issue->new(
57 project => $self->project,
58 id => $1,
59 );
60 }
61 }
62 2 $_->load for @results;
63 2 return $self->results( \@results );
64 }
65 }
66  
67 2 ▶ return unless $fallback_to_search;
Branch: 1 branch
BranchTrueFalseTotal
unless $fallback_to_search 0 2 2
68  
69 # now we have to find issues by search
70 2 ▶ if ( $self->search( load_after_search => 1, can => 'all', q => '' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->search("load_after_search", 1, "can", "all", "q", "")) 2 0 2
71 2 my $results = $self->results;
72 2 @$results = grep { $_->updated >= $after } @$results;
73 }
74 }
75  
76 3 ▶sub search {
Subroutine search: called CC=10 SCAR=23.7
Pod documented
77 3 my $self = shift;
78 3 my %args = (
79 limit => 999_999_999,
80 load_after_search => 1,
81 can => 2,
82 colspec => 'ID+Type+Status+Priority+Milestone+Owner+Summary',
83 @_
84 );
85  
86 3 ▶ if ( $args{can} !~ /^\d$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"can"} =~ /^\d$/) 2 1 3
87 2 $args{can} = $CAN_MAP{ $args{can} };
88 }
89  
90 3 my @results;
91  
92 3 my $mech = $self->mech;
93 3 my $url = $self->base_url . 'issues/list?';
94 3 for my $type (qw/can q sort colspec/) {
95 12 ▶ next unless defined $args{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{$type} 4 8 12
96 8 $url .= $type . '=' . $args{$type} . '&';
97 }
98 3 $self->fetch($url);
99  
100 3 ▶ die "Server threw an error " . $mech->response->status_line . 'when search'
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->response->is_success 0 3 3
101 unless $mech->response->is_success;
102  
103 3 my $content = $mech->response->content;
104 3 utf8::downgrade( $content, 1 );
105  
106 3 ▶ if ( $mech->title =~ /issue\s+(\d+)/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mech->title =~ /issue\s+(\d+)/i) { } 0 3 3
elsif ($mech->title =~ /issues/i) { } 3 0 3
107  
108 # get only one ticket
109 0 my $issue = Net::Google::Code::Issue->new(
110 project => $self->project,
111 id => $1,
112 );
113 0 @results = $issue;
114 }
115 elsif ( $mech->title =~ /issues/i ) {
116  
117 # get a ticket list
118 my @rows = $self->rows(
119 html => $content,
120 limit => $args{limit},
121 3 );
122  
123 3 for my $row (@rows) {
124 24 push @results,
125 Net::Google::Code::Issue->new(
126 project => $self->project,
127 %$row,
128 );
129 }
130 }
131 else {
132 0 warn "no idea what the content like";
133 0 return;
134 }
135  
136 3 ▶ if ( $args{load_after_search} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"load_after_search"}) 2 1 3
137 2 $_->load for @results;
138 }
139 3 $self->results( \@results );
140 }
141  
142 2 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
143 2 __PACKAGE__->meta->make_immutable;
144 2 1;
145  
146 __END__
« Code/Role/Pageable.pm ↑ Summary Code/Download.pm »