blib/lib/App/IMDBtop.pm

filter: Statementstmt 44.4% 28 / 63 Branchbran 8.3% 2 / 24 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 4 totaltotal 27.4% 37 / 135 CC 22 SCAR 40.8
CC
22
Cov
28%
patched_cast
132.0
print_results
42.0
add_film
17.3
CRAP 58.9
↑ Summary
1 package App::IMDBtop;
2  
3 2 ▶use 5.014000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use IMDB::Film;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use IMDB::Persons;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.001001';
12  
13 2 our $warned = 0;
14  
15 2 our (%cast_cache, %cast_count);
16 2 our ($nr, $min_count, $cache, $cache_root);
17  
18 0 ▶sub patched_cast {
Subroutine patched_cast: not called CC=11 SCAR=48.8
Pod undocumented
19 0 my IMDB::Film $self = shift;
20  
21 0 my (@cast, $tag, $person, $id, $role);
22 0 my $parser = $self->_parser(1);
23  
24 0 ▶ while($tag = $parser->get_tag('table')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag = $parser->get_tag("table")) 0 0 0
25 0 ▶ last if $tag->[1]->{class} && $tag->[1]->{class} =~ /^cast_list$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $tag->[1]{"class"} and $tag->[1]{"class"} =~ /^cast_list$/iu 0 0 0
Condition0%0/3
$tag->[1]{"class"} and $tag->[1]{"class"} =~ /^cast_list$/iu
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[1]{"class"} and $tag->[1]{"class"} =~ /^cast_list$/iu
$tag->[1]{"class"} $tag->[1]{"class"} =~ /^cast_list$/iu
Truth table0%0/3
A and B
A= $tag->[1]{"class"}B= $tag->[1]{"class"} =~ /^cast_list$/iu
ABresult
0X0
100
111
26 }
27 0 ▶ while($tag = $parser->get_tag()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag = $parser->get_tag) 0 0 0
28 0 ▶ last if $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ /fullcredits/i;
Branch: 1 branch
BranchTrueFalseTotal
if $tag->[0] eq "a" and $tag->[1]{"href"} and $tag->[1]{"href"} =~ /fullcredits/iu 0 0 0
Condition0%0/6
$tag->[0] eq "a" and $tag->[1]{"href"} and $tag->[1]{"href"} =~ /fullcredits/iu
!ll&&!rl&&r
000
$tag->[0] eq "a" and $tag->[1]{"href"}
!ll&&!rl&&r
000
MC/DC0%0/3
$tag->[0] eq "a" and $tag->[1]{"href"} and $tag->[1]{"href"} =~ /fullcredits/iu
$tag->[0] eq "a" $tag->[1]{"href"} $tag->[1]{"href"} =~ /fullcredits/iu
Truth table0%0/4
A and B and C
A= $tag->[0] eq "a"B= $tag->[1]{"href"}C= $tag->[1]{"href"} =~ /fullcredits/iu
ABCresult
0XX0
10X0
1100
1111
29 # if($tag->[0] eq 'td' && $tag->[1]{class} && $tag->[1]{class} eq 'name') {
30 0 $tag = $parser->get_tag('a');
31 0 ▶ if($tag->[1]{href} && $tag->[1]{href} =~ m#name/nm(\d+?)/#) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->[1]{"href"} and $tag->[1]{"href"} =~ m[name/nm(\d+?)/]u) 0 0 0
Condition0%0/3
$tag->[1]{"href"} and $tag->[1]{"href"} =~ m[name/nm(\d+?)/]u
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[1]{"href"} and $tag->[1]{"href"} =~ m[name/nm(\d+?)/]u
$tag->[1]{"href"} $tag->[1]{"href"} =~ m[name/nm(\d+?)/]u
Truth table0%0/3
A and B
A= $tag->[1]{"href"}B= $tag->[1]{"href"} =~ m[name/nm(\d+?)/]u
ABresult
0X0
100
111
32 0 $person = $parser->get_text;
33 0 $id = $1;
34 0 my $text = $parser->get_trimmed_text('/tr');
35 0 ($role) = $text =~ /\.\.\. (.*)$/;
36 0 ▶ push @cast, {id => $id, name => $person, role => $role} if $person;
Branch: 1 branch
BranchTrueFalseTotal
if $person 0 0 0
37 }
38 # }
39 }
40  
41 \@cast
42 0 }
43  
44 1 ▶sub add_film {
Subroutine add_film: called CC=6 SCAR=28.5
Pod undocumented
45 1 my ($crit) = @_;
46 1 chomp $crit;
47 1 my @args = (crit => $crit);
48 1 ▶ push @args, cache => $cache if defined $cache;
Branch: 1 branch
BranchTrueFalseTotal
if defined $App::IMDBtop::cache 0 1 1
49 1 ▶ push @args, cache_root => $cache_root if defined $cache_root;
Branch: 1 branch
BranchTrueFalseTotal
if defined $App::IMDBtop::cache_root 0 1 1
50 1 my $film = IMDB::Film->new(@args);
51 0 my @cast = @{ $film->cast() };
52 0 ▶ unless (@cast) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@cast) 0 0 0
53 0 ▶ warn "Installed IMDB::Film is broken, using patched cast() method\n" unless $warned;
Branch: 1 branch
BranchTrueFalseTotal
unless $App::IMDBtop::warned 0 0 0
54 0 $warned = 1;
55 0 @cast = @{ patched_cast $film };
56 }
57 0 for my $cast (@cast) {
58 0 my ($id, $name) = ($cast->{id}, $cast->{name});
59 0 $cast_cache{$id} = $name;
60 0 $cast_count{$id}++
61 }
62 }
63  
64 0 ▶sub print_results {
Subroutine print_results: not called CC=6 SCAR=37.4
Pod undocumented
65 0 my $cnt = 0;
66 0 for (
67 sort {
68 $cast_count{$b} <=> $cast_count{$a}
69 0 ▶ or $cast_cache{$a} cmp $cast_cache{$b}
Condition0%0/3
$App::IMDBtop::cast_count{$b} <=> $App::IMDBtop::cast_count{$a} || $App::IMDBtop::cast_cache{$a} cmp $App::IMDBtop::cast_cache{$b}
l!l&&r!l&&!r
000
MC/DC0%0/2
$App::IMDBtop::cast_count{$b} <=> $App::IMDBtop::cast_count{$a} || $App::IMDBtop::cast_cache{$a} cmp $App::IMDBtop::cast_cache{$b}
$App::IMDBtop::cast_count{$b} <=> $App::IMDBtop::cast_count{$a} $App::IMDBtop::cast_cache{$a} cmp $App::IMDBtop::cast_cache{$b}
Truth table0%0/3
A || B
A= $App::IMDBtop::cast_count{$b} <=> $App::IMDBtop::cast_count{$a}B= $App::IMDBtop::cast_cache{$a} cmp $App::IMDBtop::cast_cache{$b}
ABresult
1X1
011
000
70 }
71 grep {
72 0 ▶ !$min_count || $cast_count{$_} > $min_count
Condition0%0/3
!$App::IMDBtop::min_count || $App::IMDBtop::cast_count{$_} > $App::IMDBtop::min_count
l!l&&r!l&&!r
000
MC/DC0%0/2
!$App::IMDBtop::min_count || $App::IMDBtop::cast_count{$_} > $App::IMDBtop::min_count
!$App::IMDBtop::min_count $App::IMDBtop::cast_count{$_} > $App::IMDBtop::min_count
Truth table0%0/3
not(A) || B
A= !$App::IMDBtop::min_countB= $App::IMDBtop::cast_count{$_} > $App::IMDBtop::min_count
ABresult
1X1
011
000
73 } keys %cast_count) {
74 0 ▶ last if $nr && $cnt++ >= $nr;
Branch: 1 branch
BranchTrueFalseTotal
if $App::IMDBtop::nr and $cnt++ >= $App::IMDBtop::nr 0 0 0
Condition0%0/3
$App::IMDBtop::nr and $cnt++ >= $App::IMDBtop::nr
!ll&&!rl&&r
000
MC/DC0%0/2
$App::IMDBtop::nr and $cnt++ >= $App::IMDBtop::nr
$App::IMDBtop::nr $cnt++ >= $App::IMDBtop::nr
Truth table0%0/3
A and B
A= $App::IMDBtop::nrB= $cnt++ >= $App::IMDBtop::nr
ABresult
0X0
100
111
75 0 say $cast_count{$_} . ' ' . $cast_cache{$_}
76 }
77 }
78  
79 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
80 0 GetOptions (
81 'n|nr=i' => \$nr,
82 'm|min-count=i' => \$min_count,
83 'c|cache!' => \$cache,
84 'cache-root=s' => \$cache_root,
85 );
86  
87 0 ▶ add_film $_ while <>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline ARGV) and do { add_film($_) } 0 0 0
88 0 print_results
89 }
90  
91 2 1;
92 __END__
↑ Summary