| 1 | package Net::Google::Code::Download; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | with 'Net::Google::Code::TypicalRoles'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | has 'project' => ( | |||||||||||||||||||||||||||
| 10 | isa => 'Str', | ||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | has 'name' => ( | |||||||||||||||||||||||||||
| 15 | isa => 'Str', | ||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | has 'size' => ( | |||||||||||||||||||||||||||
| 20 | isa => 'Str', | ||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | has 'download_url' => ( | |||||||||||||||||||||||||||
| 25 | isa => 'Str', | ||||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | has 'count' => ( | |||||||||||||||||||||||||||
| 30 | isa => 'Int', | ||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | has 'labels' => ( | |||||||||||||||||||||||||||
| 35 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | has 'checksum' => ( | |||||||||||||||||||||||||||
| 40 | isa => 'Str', | ||||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 3 | has 'uploaded_by' => ( | |||||||||||||||||||||||||||
| 45 | isa => 'Str', | ||||||||||||||||||||||||||||
| 46 | is => 'rw', | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 3 | has 'uploaded' => ( | |||||||||||||||||||||||||||
| 50 | isa => 'Str', | ||||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=5 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 3 | ▶ | my $name = shift || $self->name; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->name
MC/DC0%0/2
shift() || $self->name
shift()
$self->name
Truth table33%1/3
A || B
A= shift()B= $self->name
| |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | die "current object doesn't have name and load() is not passed a name either" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | unless $name; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # http://code.google.com/p/net-google-code/downloads/detail?name=Net-Google-Code-0.01.tar.gz | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | my $content = | |||||||||||||||||||||||||||
| 63 | $self->fetch( $self->base_url . "downloads/detail?name=$name" ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | $self->name( $name ) unless $self->name && $self->name eq $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->name and $self->name eq $name
MC/DC0%0/2
$self->name and $self->name eq $name
$self->name
$self->name eq $name
Truth table33%1/3
A and B
A= $self->nameB= $self->name eq $name
| |||||||||||||||||||||||||||||
| 66 | 3 | return $self->parse( $content ); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 3 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | 3 | my $tree = shift; | |||||||||||||||||||||||||||
| 72 | 3 | my $need_delete = not blessed $tree; | |||||||||||||||||||||||||||
| 73 | 3 | ▶ | $tree = $self->html_tree( html => $tree ) unless blessed $tree; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | my $entry; | |||||||||||||||||||||||||||
| 76 | 3 | my $uploaded = $tree->look_down(class => 'date')->attr('title'); | |||||||||||||||||||||||||||
| 77 | 3 | ▶ | $self->uploaded( $uploaded ) if $uploaded; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 3 | my @labels_tag = $tree->look_down( class => 'label' ); | |||||||||||||||||||||||||||
| 80 | 3 | my @labels; | |||||||||||||||||||||||||||
| 81 | 3 | for my $tag ( @labels_tag ) { | |||||||||||||||||||||||||||
| 82 | 6 | push @labels, $tag->as_text; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 3 | $self->labels( \@labels ); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # parse uploaded_by and download count. | ||||||||||||||||||||||||||||
| 87 | # uploaded and labels are kind of special, so they're handleed above | ||||||||||||||||||||||||||||
| 88 | 3 | my ($meta) = $tree->look_down( id => 'issuemeta' ); | |||||||||||||||||||||||||||
| 89 | 3 | my @meta = $meta->find_by_tag_name('tr'); | |||||||||||||||||||||||||||
| 90 | 3 | for my $meta (@meta) { | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 15 | my ( $key, $value ); | |||||||||||||||||||||||||||
| 93 | 15 | $key = $meta->find_by_tag_name('th'); | |||||||||||||||||||||||||||
| 94 | 15 | ▶ | next unless $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 9 | $key = $key->as_text; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 9 | my $td = $meta->find_by_tag_name('td'); | |||||||||||||||||||||||||||
| 98 | 9 | ▶ | next unless $td; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 9 | $value = $td->as_text; | |||||||||||||||||||||||||||
| 100 | 9 | ▶ | if ( $key =~ /Uploaded.*?by/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 101 | 3 | $self->uploaded_by($value); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | elsif ( $key =~ /Downloads/ ) { | ||||||||||||||||||||||||||||
| 104 | 3 | $self->count($value); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # download_url and size | ||||||||||||||||||||||||||||
| 109 | 3 | my $desc = $tree->look_down( class => 'vt issuedescription' ); | |||||||||||||||||||||||||||
| 110 | 3 | my $box_inner = $desc->look_down( class => 'box-inner' ); | |||||||||||||||||||||||||||
| 111 | 3 | $self->download_url( $box_inner->content_array_ref->[0]->attr('href') ); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 3 | my $size = $box_inner->content_array_ref->[3]; | |||||||||||||||||||||||||||
| 114 | 3 | $size =~ s/^\D+//; | |||||||||||||||||||||||||||
| 115 | 3 | $size =~ s/\s+$//; | |||||||||||||||||||||||||||
| 116 | 3 | ▶ | $self->size( $size ) if $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # checksum | ||||||||||||||||||||||||||||
| 119 | 3 | my $span = $desc->find_by_tag_name('span'); | |||||||||||||||||||||||||||
| 120 | 3 | my $checksum = $span->content_array_ref->[0]; | |||||||||||||||||||||||||||
| 121 | 3 | ▶ | if ( $checksum =~ /^SHA1 Checksum:\s+(\w+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 3 | $self->checksum( $1 ); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 3 | ▶ | $tree->delete if $need_delete; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 4 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 129 | 4 | my %args; | |||||||||||||||||||||||||||
| 130 | 4 | ▶ | if ( @_ % 2 && ref $_[0] eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ % 2 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ % 2 and ref $_[0] eq "HASH"
@_ % 2
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ % 2B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 131 | 0 | %args = %{$_[0]}; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||
| 134 | 4 | %args = @_; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 4 | my %translations = ( filename => 'name', 'downloadcount' => 'count' ); | |||||||||||||||||||||||||||
| 138 | 4 | for my $key ( keys %translations ) { | |||||||||||||||||||||||||||
| 139 | 8 | ▶ | if ( exists $args{$key} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 4 | $args{ $translations{$key} } = $args{$key}; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 4 | return $class->SUPER::BUILDARGS(%args); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 3 | ▶ | no Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 147 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 3 | 1; | |||||||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||||||||