| 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"
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"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$_[0] // $default_url
MC/DC0%0/2
$_[0] // $default_url
$_[0]
$default_url
Truth table0%0/3
A // B
A= $_[0]B= $default_url
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $dependson = [ $dependson ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||