API/Meta/Method/APIDeclare.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran 62.5% 5 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 80.0% 32 / 40 CC 8 SCAR 19.0
CC
8
Cov
81%
add_net_api_declare
9.5
BEGIN
1.0
BEGIN
1.0
CRAP 6.7
« API/Role/Authentication.pm ↑ Summary API/Meta/Method.pm »
1 package Net::HTTP::API::Meta::Method::APIDeclare;
2 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 $Net::HTTP::API::Meta::Method::APIDeclare::VERSION = '0.14';
4 }
5  
6 # ABSTRACT: declare API
7  
8 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Net::HTTP::API::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 my @accepted_options = qw/
12 api_base_url
13 api_format
14 api_format_mode
15 api_username
16 api_password
17 authentication
18 authentication_method
19 /;
20  
21 has api_options => (
22 is => 'ro',
23 traits => ['Hash'],
24 isa => 'HashRef[Str|CodeRef]',
25 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 4 lazy => 1,
27 handles => {
28 set_api_option => 'set',
29 get_api_option => 'get',
30 },
31 );
32  
33 3 ▶sub add_net_api_declare {
Subroutine add_net_api_declare: called CC=8 SCAR=22.5
Pod undocumented
34 3 my ($meta, $name, %options) = @_;
35  
36 3 ▶ if ($options{useragent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"useragent"}) 0 3 3
37 die Net::HTTP::API::Error->new(
38 reason => "'useragent' must be a CODE ref")
39 0 ▶ unless ref $options{useragent} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options{"useragent"} eq "CODE" 0 0 0
40 0 $meta->set_api_option(useragent => delete $options{useragent});
41 }
42  
43 # XXX for backward compatibility
44 3 for my $attr (qw/base_url format format_mode username password/) {
45 15 my $attr_name = "api_" . $attr;
46 15 ▶ if (exists $options{$attr} && !exists $options{$attr_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{$attr} and not exists $options{$attr_name}) 3 12 15
Condition66%2/3
exists $options{$attr} and not exists $options{$attr_name}
!ll&&!rl&&r
1203
MC/DC50%1/2
exists $options{$attr} and not exists $options{$attr_name}
exists $options{$attr} not exists $options{$attr_name}
Truth table66%2/3
A and not(B)
A= exists $options{$attr}B= not exists $options{$attr_name}
ABresult
0X0
100
111
47 3 $options{$attr_name} = delete $options{$attr};
48 }
49 }
50  
51 3 for my $attr (@accepted_options) {
52 21 ▶ $meta->set_api_option($attr => $options{$attr}) if defined $options{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{$attr} 9 12 21
53 }
54 }
55  
56 4 1;
57  
58  
59 __END__
« API/Role/Authentication.pm ↑ Summary API/Meta/Method.pm »