BugTree.pm

filter: Statementstmt 52.8% 28 / 53 Branchbran 10.0% 1 / 10 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 81.8% 9 / 11 Podpod 100% 2 / 2 totaltotal 48.8% 41 / 84 CC 7 SCAR 23.6
CC
7
Cov
44%
fetch
30.0
__ANON__
6.8
clear_cache
2.0
CRAP 10.6
↑ Summary BugTree/Bug.pm »
1 package WWW::Bugzilla::BugTree;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Ref::Util qw( is_arrayref );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Fetch a tree of bugzilla bugs blocking a bug
10 3 our $VERSION = '0.08'; # VERSION
11  
12  
13 has ua => (
14 is => 'ro',
15 lazy => 1,
16 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 require LWP::UserAgent;
18 1 my $ua = LWP::UserAgent->new;
19 1 $ua->env_proxy;
20 1 $ua;
21 },
22 3 );
23  
24  
25 3 ▶my $default_url = $ENV{BUG_TREE_URL} // "https://landfill.bugzilla.org/bugzilla-4.2-branch";
Condition50%1/2
$ENV{"BUG_TREE_URL"} // "https://landfill.bugzilla.org/bugzilla-4.2-branch"
l!l
03
MC/DC0%0/1
$ENV{"BUG_TREE_URL"} // "https://landfill.bugzilla.org/bugzilla-4.2-branch"
$ENV{"BUG_TREE_URL"}
Truth table50%1/2
A
A= $ENV{"BUG_TREE_URL"}
Aresult
11
00
26  
27 has url => (
28 is => 'ro',
29 lazy => 1,
30 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 require URI;
32 1 URI->new($default_url);
33 },
34 1 ▶ coerce => sub {
Subroutine __ANON__: called CC=3 SCAR=19.2
35 0 ▶ ref $_[0] ? $_[0] : do { require URI; URI->new($_[0] // $default_url) },
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 0 1
Condition0%0/3
$_[0] // $default_url
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] // $default_url
$_[0] $default_url
Truth table0%0/3
A // B
A= $_[0]B= $default_url
ABresult
1X1
011
000
36 },
37 3 );
38  
39 has _cache => (
40 is => 'ro',
41 1 ▶ default => sub { { } },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 3 init_arg => undef,
43 );
44  
45  
46 sub fetch
47 0 ▶{
Subroutine fetch: not called CC=5 SCAR=34.0
Pod documented
48 0 my($self, $bug_id) = @_;
49
50 return $self->_cache->{$bug_id}
51 0 ▶ if exists $self->_cache->{$bug_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_cache->{$bug_id} 0 0 0
52
53 0 my $url = $self->url->clone;
54 0 $url->path((do { my $path = $url->path; $path =~ s{/$}{}; $path }) . "/show_bug.cgi");
55 0 $url->query_form(
56 id => $bug_id,
57 ctype => 'xml',
58 );
59
60 0 my $res = $self->ua->get($url);
61
62 0 ▶ die $url . " " . $res->status_line
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
63 unless $res->is_success;
64  
65 0 require WWW::Bugzilla::BugTree::Bug;
66 0 my $b = WWW::Bugzilla::BugTree::Bug->new(
67 url => $url,
68 res => $res,
69 id => $bug_id,
70 );
71
72 0 $self->_cache->{$bug_id} = $b;
73
74 0 my $dependson = $b->as_hashref->{bug}->{dependson};
75 0 ▶ $dependson = [] unless defined $dependson;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dependson 0 0 0
76 0 ▶ $dependson = [ $dependson ]
Branch: 1 branch
BranchTrueFalseTotal
unless is_arrayref($dependson) 0 0 0
77 unless is_arrayref $dependson;
78
79 0 @{ $b->children } = map { $self->fetch($_) } sort @$dependson;
80
81 0 $b;
82 }
83  
84  
85 sub clear_cache
86 0 ▶{
Subroutine clear_cache: not called CC=1 SCAR=6.9
Pod documented
87 0 my($self) = @_;
88 0 %{ $self->_cache } = ();
89 }
90  
91 3 1;
92  
93 __END__
↑ Summary BugTree/Bug.pm »