FederatedLogin/Extension.pm

filter: Statementstmt 34.0% 31 / 91 Branchbran 18.1% 4 / 22 Conditioncond 13.3% 2 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 45.4% 5 / 11 Podpod 100% 3 / 3 totaltotal 29.6% 45 / 152 CC 21 SCAR 28.1
CC
21
Cov
29%
_extract_attributes_by_ns
42.0
_extract_attributes_by_uri
20.0
__ANON__
18.0
CRAP 16.6
« FederatedLogin.pm ↑ Summary FederatedLogin/Apps/Discoverer.pm »
1 package Net::Google::FederatedLogin::Extension;
2 {
3 5 $Net::Google::FederatedLogin::Extension::VERSION = '0.8.0';
4 }
5 # ABSTRACT: Storage and methods for OpenID extensions, both requesting information and receiving data.
6  
7 5 ▶use Moose 0.51;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 5 has ns => (
11 is => 'rw',
12 isa => 'Str',
13 required => 1,
14 );
15  
16  
17 5 has uri => (
18 is => 'rw',
19 isa => 'Str',
20 required => 1,
21 );
22  
23  
24 5 has attributes => (
25 is => 'rw',
26 isa => 'HashRef',
27 required => 1,
28 trigger => \&_flatten_attributes,
29 );
30  
31 2 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=7 SCAR=28.9
32 2 my $orig = shift;
33 2 my $class = shift;
34
35 2 my $args;
36 2 ▶ if(@_ == 1 && ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 2 0 2
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
002
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
37 2 $args = $_[0];
38 } else {
39 0 $args = {@_};
40 }
41 2 ▶ if($args->{cgi} or $args->{cgi_params}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'cgi'} or $args->{'cgi_params'}) { } 0 2 2
Condition33%1/3
$args->{"cgi"} or $args->{"cgi_params"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$args->{"cgi"} or $args->{"cgi_params"}
$args->{"cgi"} $args->{"cgi_params"}
Truth table33%1/3
A or B
A= $args->{"cgi"}B= $args->{"cgi_params"}
ABresult
1X1
011
000
42 0 my $new_args;
43 0 ▶ if($args->{uri}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'uri'}) { } 0 0 0
elsif ($args->{'ns'}) { } 0 0 0
44 0 $new_args = _extract_attributes_by_uri($args);
45 } elsif($args->{ns}) {
46 0 $new_args = _extract_attributes_by_ns($args);
47 } else {
48 0 die 'Unable to determine extension details';
49 }
50 0 return $class->$orig($new_args);
51 } else {
52 2 return $class->$orig(@_);
53 }
54 5 };
55  
56 0 ▶sub _extract_attributes_by_uri {
Subroutine _extract_attributes_by_uri: not called CC=4 SCAR=30.0
57 0 my $args = shift;
58
59 0 my $cgi = $args->{cgi};
60 0 my $cgi_params = $args->{cgi_params};
61 0 my $uri = $args->{uri};
62
63 0 ▶ my @openid_params = grep {/^openid\./} $cgi ? $cgi->param() : keys %$cgi_params;
Branch: 1 branch
BranchTrueFalseTotal
$cgi ? : 0 0 0
64 0 ▶ (my $ns_param) = grep {($cgi ? $cgi->param($_) : $cgi_params->{$_}) eq $uri} grep {/^openid\.ns\./} @openid_params;
Branch: 1 branch
BranchTrueFalseTotal
$cgi ? : 0 0 0
65 0 ▶ if($ns_param) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns_param) 0 0 0
66 0 $args->{ns} = substr($ns_param, 10);
67 0 return _extract_attributes_by_ns($args);
68 }
69
70 0 return $args;
71 }
72  
73 0 ▶sub _extract_attributes_by_ns {
Subroutine _extract_attributes_by_ns: not called CC=6 SCAR=37.4
74 0 my $args = shift;
75
76 0 my $cgi = $args->{cgi};
77 0 my $cgi_params = $args->{cgi_params};
78 0 my $ns = $args->{ns};
79
80 0 ▶ $args->{uri} ||= $cgi ? $cgi->param("openid.ns.$ns") : $cgi_params->{"openid.ns.$ns"};
Branch: 1 branch
BranchTrueFalseTotal
$cgi ? : 0 0 0
Condition0%0/3
$args->{"uri"} ||= $cgi ? $cgi->param("openid.ns.$ns") : $$cgi_params{"openid.ns.$ns"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"uri"} ||= $cgi ? $cgi->param("openid.ns.$ns") : $$cgi_params{"openid.ns.$ns"}
$args->{"uri"} $cgi ? $cgi->param("openid.ns.$ns") : $$cgi_params{"openid.ns.$ns"}
Truth table0%0/3
A ||= B
A= $args->{"uri"}B= $cgi ? $cgi->param("openid.ns.$ns") : $$cgi_params{"openid.ns.$ns"}
ABresult
1X1
011
000
81
82 0 my $prefix = "openid.$ns.";
83 0 my $prefix_len = length($prefix);
84 0 my %attributes;
85 0 ▶ if($cgi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cgi) { } 0 0 0
86 0 my %signed_params = map {("openid.$_" => 1)} split /,/, $cgi->param('openid.signed');
87 0 ▶ %attributes = (map {substr($_, $prefix_len) => scalar $cgi->param($_)} grep {/^\Q$prefix\E/ and $signed_params{$_}} $cgi->param());
Condition0%0/3
/^\Q$prefix\E/ && $signed_params{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
/^\Q$prefix\E/ && $signed_params{$_}
/^\Q$prefix\E/ $signed_params{$_}
Truth table0%0/3
A && B
A= /^\Q$prefix\E/B= $signed_params{$_}
ABresult
0X0
100
111
88 } else {
89 0 my %signed_params = map {("openid.$_" => 1)} split /,/, $cgi_params->{'openid.signed'};
90 0 ▶ %attributes = (map {substr($_, $prefix_len) => $cgi_params->{$_}} grep {/^\Q$prefix\E/ and $signed_params{$_}} keys %$cgi_params);
Condition0%0/3
/^\Q$prefix\E/ && $signed_params{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
/^\Q$prefix\E/ && $signed_params{$_}
/^\Q$prefix\E/ $signed_params{$_}
Truth table0%0/3
A && B
A= /^\Q$prefix\E/B= $signed_params{$_}
ABresult
0X0
100
111
91 }
92 0 $args->{attributes} = \%attributes;
93
94 0 return $args;
95 }
96  
97  
98 0 ▶sub get_parameter_string {
Subroutine get_parameter_string: not called CC=1 SCAR=6.9
Pod documented
99 0 my $self = shift;
100 0 my $ns = $self->ns;
101
102 0 my $params = sprintf 'openid.ns.%s=%s', $ns, $self->uri;
103
104 0 my $attributes = $self->attributes;
105 0 $params .= _parameterise_hash("openid.$ns", $attributes);
106
107 0 return $params;
108 }
109  
110 0 ▶sub _parameterise_hash {
Subroutine _parameterise_hash: not called CC=2 SCAR=17.9
111 0 my $prefix = shift;
112 0 my $hash = shift;
113
114 0 my $params = '';
115 0 $params .= sprintf '&%s.%s=%s', $prefix, $_, $hash->{$_} foreach(sort keys %$hash);
116 0 return $params;
117 }
118  
119  
120 0 ▶sub get_parameter {
Subroutine get_parameter: not called CC=2 SCAR=17.9
Pod documented
121 0 my $self = shift;
122 0 my $param = shift;
123
124 0 ▶ die "$param is not an available parameter" unless exists $self->attributes->{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->attributes->{$param} 0 0 0
125 0 return $self->attributes->{$param};
126 }
127  
128  
129 0 ▶sub set_parameter {
Subroutine set_parameter: not called CC=2 SCAR=17.9
Pod documented
130 0 my $self = shift;
131 0 my %params = @_;
132
133 0 _flatten_hash(\%params);
134
135 0 $self->attributes->{$_} = $params{$_} foreach keys %params;
136 }
137  
138 2 ▶sub _flatten_attributes {
Subroutine _flatten_attributes: called CC=1 SCAR=0.0
139 2 my $self = shift;
140 2 my $attributes = shift;
141
142 2 _flatten_hash($attributes);
143 }
144  
145 3 ▶sub _flatten_hash {
Subroutine _flatten_hash: called CC=4 SCAR=13.9
146 3 my $hash = shift;
147
148 3 foreach my $key (keys %$hash) {
149 5 my $value = $hash->{$key};
150 5 ▶ if(ref $value eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 1 4 5
151 1 _flatten_hash($value);
152 1 $hash->{"$key.$_"} = $value->{$_} foreach keys %$value;
153 1 delete $hash->{$key};
154 }
155 }
156 }
157  
158 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 5 __PACKAGE__->meta->make_immutable;
160  
161 5 1;
162  
163 __END__
« FederatedLogin.pm ↑ Summary FederatedLogin/Apps/Discoverer.pm »