| 1 | package Net::Google::Code::Issue::Comment; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Net::Google::Code::Issue::Attachment; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Net::Google::Code::Issue::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Net::Google::Code::DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | with 'Net::Google::Code::Role::HTMLTree'; | |||||||||||||||||||||||||||
| 7 | 9 | extends 'Net::Google::Code::Issue::Base'; | |||||||||||||||||||||||||||
| 8 | 9 | with 'Net::Google::Code::Role::Authentication'; | |||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Params::Validate ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use XML::FeedPP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 20 | ▶ | has 'updates' => ( isa => 'HashRef', is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 9 | has 'author' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||
| 16 | 9 | has 'content' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||
| 17 | 9 | has 'sequence' => ( isa => 'Int', is => 'rw' ); | |||||||||||||||||||||||||||
| 18 | 9 | has 'date' => ( isa => 'DateTime', is => 'rw' ); | |||||||||||||||||||||||||||
| 19 | has 'attachments' => ( | ||||||||||||||||||||||||||||
| 20 | isa => 'ArrayRef[Net::Google::Code::Issue::Attachment]', | ||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | 18 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 9 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 9 | has 'issue_id' => ( | |||||||||||||||||||||||||||
| 26 | isa => 'Int', | ||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 8 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 8 | my $element = shift; | |||||||||||||||||||||||||||
| 33 | 8 | my $need_delete = not blessed $element; | |||||||||||||||||||||||||||
| 34 | 8 | ▶ | $element = $self->html_tree( html => $element ) unless blessed $element; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | my $author = $element->look_down( class => 'author' ); | |||||||||||||||||||||||||||
| 37 | 8 | my @a = $author->find_by_tag_name('a'); | |||||||||||||||||||||||||||
| 38 | 8 | $self->sequence( $a[0]->content_array_ref->[0] ); | |||||||||||||||||||||||||||
| 39 | 8 | $self->author( $a[1]->content_array_ref->[0] ); | |||||||||||||||||||||||||||
| 40 | 8 | $self->date(Net::Google::Code::DateTime->new_from_string( $element->look_down( class => 'date' )->attr('title') )); | |||||||||||||||||||||||||||
| 41 | 8 | my $content = $element->find_by_tag_name('pre')->as_text; | |||||||||||||||||||||||||||
| 42 | 8 | $content =~ s/^\s+//; | |||||||||||||||||||||||||||
| 43 | 8 | $content =~ s/\s+$//; | |||||||||||||||||||||||||||
| 44 | 8 | $content =~ s/\r\n/\n/g; | |||||||||||||||||||||||||||
| 45 | 8 | ▶ | $self->content($content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | unless $content eq '(No comment was entered for this change.)'; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 8 | my $updates = $element->look_down( class => 'updates' ); | |||||||||||||||||||||||||||
| 49 | 8 | ▶ | if ($updates) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 5 | my $box_inner = $element->look_down( class => 'box-inner' ); | |||||||||||||||||||||||||||
| 51 | 5 | my $content = $box_inner->content_array_ref; | |||||||||||||||||||||||||||
| 52 | 5 | ▶ | while (@$content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 5 | my $tag = shift @$content; | |||||||||||||||||||||||||||
| 54 | 5 | my $value = shift @$content; | |||||||||||||||||||||||||||
| 55 | 5 | ▶ | if ( ref $value && $value->as_HTML =~ m!<br />! ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value and $value->as_HTML =~ m[<br />]
MC/DC0%0/2
ref $value and $value->as_HTML =~ m[<br />]
ref $value
$value->as_HTML =~ m[<br />]
Truth table33%1/3
A and B
A= ref $valueB= $value->as_HTML =~ m[<br />]
| |||||||||||||||||||||||||||||
| 56 | # this happens when there's no value for $tag | ||||||||||||||||||||||||||||
| 57 | 0 | $value = ''; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||
| 60 | 5 | shift @$content; # this is for the <br> | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | my $key = $tag->content_array_ref->[0]; | |||||||||||||||||||||||||||
| 64 | 5 | $key =~ s/:$//; | |||||||||||||||||||||||||||
| 65 | 5 | $value =~ s/^\s+//; | |||||||||||||||||||||||||||
| 66 | 5 | $value =~ s/\s+$//; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | ▶ | if ( $key eq 'Labels' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # $value here is like "-Pri-2 -Area-Unknown Pri-3 Area-BrowserUI" | ||||||||||||||||||||||||||||
| 71 | 1 | my @items = split /\s+/, $value; | |||||||||||||||||||||||||||
| 72 | 1 | for my $value (@items) { | |||||||||||||||||||||||||||
| 73 | 1 | push @{$self->updates->{labels}}, $value; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||
| 77 | 4 | $self->updates->{ lc $key } = $value; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 8 | my $att_tag = $element->look_down( class => 'attachments' ); | |||||||||||||||||||||||||||
| 84 | 8 | my @attachments; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 8 | ▶ | @attachments = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | Net::Google::Code::Issue::Attachment->parse_attachments($att_tag) | ||||||||||||||||||||||||||||
| 88 | if $att_tag; | ||||||||||||||||||||||||||||
| 89 | 8 | $self->attachments( \@attachments ); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 8 | ▶ | $self->delete if $need_delete; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 8 | return 1; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub parse_hybrid { | ||||||||||||||||||||||||||
|
Subroutine
parse_hybrid: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 98 | 0 | my $need_delete = not blessed $element; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | $element = $self->html_tree( html => $element ) unless blessed $element; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | my $updates = $element->look_down( class => 'updates' ); | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($updates) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | my $box_inner = $element->look_down( class => 'box-inner' ); | |||||||||||||||||||||||||||
| 103 | 0 | my $content = $box_inner->content_array_ref; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | while (@$content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | my $tag = shift @$content; | |||||||||||||||||||||||||||
| 106 | 0 | my $value = shift @$content; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( ref $value && $value->as_HTML =~ m!<br />! ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and $value->as_HTML =~ m[<br />]
MC/DC0%0/2
ref $value and $value->as_HTML =~ m[<br />]
ref $value
$value->as_HTML =~ m[<br />]
Truth table0%0/3
A and B
A= ref $valueB= $value->as_HTML =~ m[<br />]
| |||||||||||||||||||||||||||||
| 108 | # this happens when there's no value for $tag | ||||||||||||||||||||||||||||
| 109 | 0 | $value = ''; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||
| 112 | 0 | shift @$content; # this is for the <br> | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $key = $tag->content_array_ref->[0]; | |||||||||||||||||||||||||||
| 116 | 0 | $key =~ s/:$//; | |||||||||||||||||||||||||||
| 117 | 0 | $value =~ s/^\s+//; | |||||||||||||||||||||||||||
| 118 | 0 | $value =~ s/\s+$//; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( $key ne 'Labels' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | $self->updates->{ lc $key } = $value; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | my $att_tag = $element->look_down( class => 'attachments' ); | |||||||||||||||||||||||||||
| 127 | 0 | my @attachments; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | @attachments = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | Net::Google::Code::Issue::Attachment->parse_attachments($att_tag) | ||||||||||||||||||||||||||||
| 131 | if $att_tag; | ||||||||||||||||||||||||||||
| 132 | 0 | $self->attachments( \@attachments ); | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | $element->delete if $need_delete; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | return 1; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 9 | ▶ | sub _load_from_xml { | ||||||||||||||||||||||||||
|
Subroutine
_load_from_xml: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 138 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | 9 | my $ref = | |||||||||||||||||||||||||||
| 140 | Net::Google::Code::Issue::Util->translate_from_xml( shift, | ||||||||||||||||||||||||||||
| 141 | type => 'comment' ); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 9 | for my $k ( keys %$ref ) { | |||||||||||||||||||||||||||
| 144 | 86 | ▶ | if ( $self->can($k) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 32 | $self->{$k} = $ref->{$k}; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 9 | return $self; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 153 | 1 | validate( @_, { max_results => { optional => 1, type => SCALAR }, } ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | my %args = ( max_results => 1_000_000_000, @_ ); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 1 | my $url = $self->feeds_issues_url . '/' . $self->issue_id . | |||||||||||||||||||||||||||
| 158 | '/comments/full?'; | ||||||||||||||||||||||||||||
| 159 | 1 | require URI::Escape; | |||||||||||||||||||||||||||
| 160 | 1 | for my $k ( keys %args ) { | |||||||||||||||||||||||||||
| 161 | 1 | ▶ | next unless $args{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 1 | my $v = $args{$k}; | |||||||||||||||||||||||||||
| 163 | 1 | $k =~ s/_/-/g; | |||||||||||||||||||||||||||
| 164 | 1 | $url .= "$k=" . URI::Escape::uri_escape($v) . '&'; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | my $ua = $self->ua; | |||||||||||||||||||||||||||
| 168 | 1 | my $res = $ua->get($url); | |||||||||||||||||||||||||||
| 169 | 1 | ▶ | if ( $res->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 1 | my $feed = XML::FeedPP->new($res->content); | |||||||||||||||||||||||||||
| 171 | 1 | my @items = $feed->get_item; | |||||||||||||||||||||||||||
| 172 | my @list = map { | ||||||||||||||||||||||||||||
| 173 | 1 | my $t = Net::Google::Code::Issue::Comment->new( | |||||||||||||||||||||||||||
| 174 | 18 | map { $_ => $self->$_ } | |||||||||||||||||||||||||||
| 175 | 9 | grep { $self->$_ } qw/project email password token issue_id/ | |||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||
| 177 | 9 | $t->_load_from_xml($_); | |||||||||||||||||||||||||||
| 178 | } @items; | ||||||||||||||||||||||||||||
| 179 | 1 | ▶ | return wantarray ? @list : \@list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||
| 182 | 0 | die "try to get $url failed: " | |||||||||||||||||||||||||||
| 183 | . $res->status_line . "\n" | ||||||||||||||||||||||||||||
| 184 | . $res->content; | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 9 | ▶ | no Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 189 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 190 | 9 | 1; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | __END__ | ||||||||||||||||||||||||||||