OAuth2/Args.pm

filter: Statementstmt 73.9% 34 / 46 Branchbran 70.0% 14 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 70.5% 55 / 78 CC 11 SCAR 17.1
CC
11
Cov
73%
extract_option
12.0
copy_option
7.0
assert_options_empty
3.2
CRAP 5.5
« OAuth2/AccessToken/Bearer.pm ↑ Summary OAuth2/ServiceProvider/Dwolla.pm »
1 package LWP::Authen::OAuth2::Args;
2  
3 # ABSTRACT: Args
4 14 our $VERSION = '0.20'; # VERSION
5  
6 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 14 ▶use Carp qw(croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 14 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 14 our @EXPORT_OK = qw(extract_option copy_option assert_options_empty);
14  
15 # Blessed empty hash.
16 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 7 return bless {}, shift;
18 }
19  
20 0 ▶sub extract_option {
Subroutine extract_option: not called CC=3 SCAR=24.8
Pod undocumented
21 0 my $obj = shift;
22 0 my $opts = shift;
23 0 my $name = shift;
24 0 my $has_default = @_;
25 0 my $default = shift;
26  
27 0 ▶ if (exists $opts->{$name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{$name}) { } 0 0 0
elsif ($has_default) { } 0 0 0
28 0 return delete $opts->{$name};
29 }
30 elsif ($has_default) {
31 0 return $default;
32 }
33 else {
34 0 croak("'$name' is required, cannot be missing");
35 }
36 }
37  
38 196 ▶sub copy_option {
Subroutine copy_option: called CC=7 SCAR=19.5
Pod undocumented
39 196 my $obj = shift;
40 196 my $opts = shift;
41 196 my $name = shift;
42 196 my $has_default = @_;
43 196 my $default = shift;
44  
45 196 ▶ if (not exists $obj->{$name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $obj->{$name}) { } 194 2 196
elsif (exists $opts->{$name}) { } 1 1 2
46 194 ▶ if (exists $opts->{$name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts->{$name}) { } 23 171 194
elsif ($has_default) { } 170 1 171
47 23 my $value = delete $opts->{$name};
48 23 ▶ if (defined($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 22 1 23
elsif ($has_default) { } 0 1 1
49 22 $obj->{$name} = $value;
50 }
51 elsif ($has_default) {
52 0 $obj->{$name} = $default;
53 }
54 else {
55 1 croak("'$name' is required, cannot be undef");
56 }
57 }
58 elsif ($has_default) {
59 170 $obj->{$name} = $default;
60 }
61 else {
62 1 croak("'$name' is required, cannot be missing");
63 }
64 }
65 elsif (exists $opts->{$name}) {
66 # This should not be hit, but if it was, it would be confusing
67 1 confess("Refusing to copy '$name' that is already in hash");
68 }
69 }
70  
71 2 ▶sub assert_options_empty {
Subroutine assert_options_empty: called CC=3 SCAR=11.8
Pod undocumented
72 2 my ($obj, $opts) = @_;
73 2 my @keys = sort keys %$opts;
74 2 ▶ if (1 == @keys) {
Branch: 2 branches
BranchTrueFalseTotal
if (1 == @keys) { } 1 1 2
elsif (@keys) { } 0 1 1
75 1 croak("Unexpected parameter: '$keys[0]'");
76 }
77 elsif (@keys) {
78 0 my $extra = "'" . (join "', '", @keys) . "'";
79 0 croak("Extra parameters: $extra");
80 }
81 }
82  
83 14 1;
84  
85 __END__
« OAuth2/AccessToken/Bearer.pm ↑ Summary OAuth2/ServiceProvider/Dwolla.pm »