Lite/Message.pm

filter: Statementstmt 40.8% 58 / 142 Branchbran 13.3% 4 / 30 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 41.9% 13 / 31 Podpod 0.0% 0 / 24 totaltotal 30.1% 76 / 252 CC 29 SCAR 21.1
CC
29
Cov
34%
set_extra
30.0
get
13.1
get_ns_alias
12.0
CRAP 8.2
« Lite/Util/URI.pm ↑ Summary Lite/Util/XRI.pm »
1 package OpenID::Lite::Message;
2  
3 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use OpenID::Lite::Constants::Namespace qw(SIGNON_1_0 SIGNON_1_1 SPEC_2_0);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use OpenID::Lite::Message::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 my $REQUEST_DECODER = OpenID::Lite::Message::Decoder->new;
12  
13 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 2 my ( $class, %params ) = @_;
15 2 my $self = bless {
16 _params => {},
17 _extension_params => {},
18 _extra_params => {},
19 _extension_namespaces => {},
20 }, $class;
21 2 return $self;
22 }
23  
24 0 ▶sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my $self = shift;
26 0 my $class = ref $self;
27 0 my $copied = Storable::dclone($self);
28 0 return bless $copied, $class;
29 }
30  
31 0 ▶sub register_extension_namespace {
Subroutine register_extension_namespace: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my ( $self, $ext_name, $ext_ns ) = @_;
33 0 $self->{_extension_namespaces}{$ext_name} = $ext_ns;
34 }
35  
36 21 ▶sub get {
Subroutine get: called CC=5 SCAR=25.7
Pod undocumented
37 21 my ( $self, $key ) = @_;
38 21 ▶ if ($key =~ /^([^.]+)\.([^.]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^([^.]+)\.([^.]+)$/) { } 0 21 21
39 0 my $ext_name = $1;
40 0 my $ext_key = $2;
41 0 ▶ if ( $ext_name eq 'ns' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext_name eq 'ns') { } 0 0 0
42 return exists $self->{_extension_namespaces}{$ext_key}
43 0 ▶ ? $self->{_extension_namespaces}{$ext_key}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_extension_namespaces'}{$ext_key} ? : 0 0 0
44 : undef;;
45 } else {
46 0 return $self->get_extension($ext_name, $ext_key);
47 }
48 } else {
49 return exists $self->{_params}{$key}
50 21 ▶ ? $self->{_params}{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_params'}{$key} ? : 21 0 21
51 : undef;
52 }
53 }
54  
55 0 ▶sub get_ns_alias {
Subroutine get_ns_alias: not called CC=3 SCAR=24.8
Pod undocumented
56 0 my ( $self, $ns ) = @_;
57 0 for my $alias ( keys %{ $self->{_extension_namespaces} } ) {
58 0 ▶ return $alias if $ns eq $self->{_extension_namespaces}{$alias};
Branch: 1 branch
BranchTrueFalseTotal
if $ns eq $self->{"_extension_namespaces"}{$alias} 0 0 0
59 }
60 0 return;
61 }
62  
63 0 ▶sub has_key {
Subroutine has_key: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my ( $self, $key ) = @_;
65 0 return exists $self->{_params}{$key};
66 }
67  
68 0 ▶sub get_extension {
Subroutine get_extension: not called CC=3 SCAR=24.8
Pod undocumented
69 0 my ( $self, $ext_name, $key ) = @_;
70 return ( exists $self->{_extension_params}{$ext_name}
71 && exists $self->{_extension_params}{$ext_name}{$key} )
72 0 ▶ ? $self->{_extension_params}{$ext_name}{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_extension_params'}{$ext_name} && exists $self->{'_extension_params'}{$ext_name}{$key} ? : 0 0 0
Condition0%0/3
exists $self->{"_extension_params"}{$ext_name} and exists $self->{"_extension_params"}{$ext_name}{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"_extension_params"}{$ext_name} and exists $self->{"_extension_params"}{$ext_name}{$key}
exists $self->{"_extension_params"}{$ext_name} exists $self->{"_extension_params"}{$ext_name}{$key}
Truth table0%0/3
A and B
A= exists $self->{"_extension_params"}{$ext_name}B= exists $self->{"_extension_params"}{$ext_name}{$key}
ABresult
0X0
100
111
73 : undef;
74 }
75  
76 0 ▶sub get_extra {
Subroutine get_extra: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my ( $self, $key ) = @_;
78 return exists $self->{_extra_params}{$key}
79 0 ▶ ? $self->{_extra_params}{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_extra_params'}{$key} ? : 0 0 0
80 : undef;
81 }
82  
83 0 ▶sub get_keys {
Subroutine get_keys: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my $self = shift;
85 0 my @keys = keys %{ $self->{_params} };
86 0 return \@keys;
87 }
88  
89 0 ▶sub get_extension_keys {
Subroutine get_extension_keys: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my $self = shift;
91 0 my $alias = shift;
92 0 my @keys = keys %{ $self->{_extension_params}{$alias} };
93 0 return \@keys;
94 }
95  
96 0 ▶sub get_extension_args {
Subroutine get_extension_args: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my $self = shift;
98 0 my $alias = shift;
99 0 ▶ return unless exists $self->{_extension_params}{$alias};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_extension_params"}{$alias} 0 0 0
100 0 return $self->{_extension_params}{$alias};
101 }
102  
103 0 ▶sub get_extra_keys {
Subroutine get_extra_keys: not called CC=1 SCAR=6.9
Pod undocumented
104 0 my $self = shift;
105 0 my @keys = keys %{ $self->{_extra_params} };
106 0 return \@keys;
107 }
108  
109 8 ▶sub set {
Subroutine set: called CC=5 SCAR=23.7
Pod undocumented
110 8 my ( $self, $key, $value ) = @_;
111 8 ▶ return unless ( defined $key && defined $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and defined $value 0 8 8
Condition33%1/3
defined $key and defined $value
!ll&&!rl&&r
008
MC/DC0%0/2
defined $key and defined $value
defined $key defined $value
Truth table33%1/3
A and B
A= defined $keyB= defined $value
ABresult
0X0
100
111
112 8 ▶ if ($key =~ /^([^.]+)\.([^.]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^([^.]+)\.([^.]+)$/) { } 0 8 8
113 0 my $ext_name = $1;
114 0 my $ext_key = $2;
115 0 ▶ if ($ext_name eq 'ns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext_name eq 'ns') { } 0 0 0
116 0 $self->register_extension_namespace($ext_key, $value);
117 } else {
118 0 $self->set_extension($ext_name, $ext_key, $value);
119 }
120 } else {
121 8 $self->{_params}{$key} = $value;
122 }
123 }
124  
125 0 ▶sub set_extension {
Subroutine set_extension: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my ( $self, $ext_name, $key, $value ) = @_;
127 0 $self->{_extension_params}{$ext_name}{$key} = $value;
128 }
129  
130 0 ▶sub set_extra {
Subroutine set_extra: not called CC=5 SCAR=34.0
Pod undocumented
131 0 my ( $self, $key, $value ) = @_;
132 0 ▶ if ( defined $key && defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key and defined $value) 0 0 0
Condition0%0/3
defined $key and defined $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and defined $value
defined $key defined $value
Truth table0%0/3
A and B
A= defined $keyB= defined $value
ABresult
0X0
100
111
133 0 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 0 0
134 0 ▶ $self->{_extra_params}{$key} = @$value > 1 ? $value : $value->[0];
Branch: 1 branch
BranchTrueFalseTotal
@$value > 1 ? : 0 0 0
135 } else {
136 0 $self->{_extra_params}{$key} = $value
137 }
138 }
139  
140 }
141  
142 0 ▶sub from_key_value {
Subroutine from_key_value: not called CC=2 SCAR=17.9
Pod undocumented
143 0 my ( $class, $body ) = @_;
144 0 my $params = $class->new;
145 0 for my $line ( split /\n/, $body ) {
146 0 my ($key, $value) = split /:/, $line, 2;
147 0 $params->set( $key, $value );
148 }
149 0 return $params;
150 }
151  
152 0 ▶sub from_request {
Subroutine from_request: not called CC=1 SCAR=6.9
Pod undocumented
153 0 my ( $class, $request ) = @_;
154 0 return $REQUEST_DECODER->decode($request);
155 }
156  
157 1 ▶sub to_key_value {
Subroutine to_key_value: called CC=1 SCAR=0.0
Pod undocumented
158 1 my $self = shift;
159  
160 #$self->set( ns => SIGNON_1_0 ) unless $self->get('ns');
161 return join(
162 "\n",
163 map( sprintf( q{%s:%s}, $_, $self->{_params}{$_} ),
164 1 sort keys %{ $self->{_params} } )
165 )."\n";
166 }
167  
168 1 ▶sub to_post_body {
Subroutine to_post_body: called CC=1 SCAR=0.0
Pod undocumented
169 1 my $self = shift;
170  
171 #$self->set( ns => SIGNON_1_0 ) unless $self->get('ns');
172 1 my $params = $self->to_hash;
173 return join(
174 "&",
175 map( sprintf( q{%s=%s},
176 URI::Escape::uri_escape_utf8($_),
177 URI::Escape::uri_escape_utf8( $params->{$_} ) ),
178 1 sort keys %{ $params } )
179 );
180 }
181  
182 0 ▶sub to_url {
Subroutine to_url: not called CC=2 SCAR=17.9
Pod undocumented
183 0 my ( $self, $uri ) = @_;
184  
185 #$self->set( ns => SIGNON_1_0 ) unless $self->get('ns');
186 0 ▶ $uri = URI->new($uri) unless ref $uri eq 'URI';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $uri eq "URI" 0 0 0
187 0 $uri->query_form( %{ $self->to_hash } );
188 0 return $uri;
189 }
190  
191 1 ▶sub to_hash {
Subroutine to_hash: called CC=5 SCAR=19.8
Pod undocumented
192 1 my $self = shift;
193 2 my %params = map { ( sprintf( q{openid.%s}, $_ ), $self->{_params}{$_} ) }
194 1 keys %{ $self->{_params} };
195 1 for my $ext_name ( keys %{ $self->{_extension_namespaces} } ) {
196 0 my $key = sprintf( q{openid.ns.%s}, $ext_name );
197 0 my $value = $self->{_extension_namespaces}{$ext_name};
198 0 $params{$key} = $value;
199 }
200 1 for my $ext_name ( keys %{ $self->{_extension_params} } ) {
201 0 my $ext_hash = $self->{_extension_params}{$ext_name};
202 0 for my $ext_key ( keys %$ext_hash ) {
203 0 my $key = sprintf( q{openid.%s.%s}, $ext_name, $ext_key );
204 0 my $value = $ext_hash->{$ext_key};
205 0 $params{$key} = $value;
206 }
207 }
208 1 for my $key ( keys %{ $self->{_extra_params} } ) {
209 0 $params{$key} = $self->{_extra_params}{$key};
210 }
211 1 return \%params;
212 }
213  
214 1 ▶sub set_signed {
Subroutine set_signed: called CC=3 SCAR=11.7
Pod undocumented
215 1 my $self = shift;
216 1 my @keys = grep { $_ ne q{sig} } keys %{ $self->{_params} };
217 1 for my $ext_name ( keys %{ $self->{_extension_namespaces} } ) {
218 0 push(@keys, sprintf(q{ns.%s}, $ext_name));
219 0 for my $ext_key ( keys %{ $self->{_extension_params}{$ext_name} } ) {
220 0 push(@keys, sprintf(q{%s.%s},$ext_name, $ext_key));
221 }
222 }
223 1 @keys = grep { $self->get($_) } @keys;
224 1 push(@keys, q{signed});
225 1 $self->set( signed => join(',', sort @keys));
226 }
227  
228 0 ▶sub is_openid1 {
Subroutine is_openid1: not called CC=2 SCAR=17.9
Pod undocumented
229 0 my $self = shift;
230 0 my $ns = $self->get('ns');
231 0 ▶ return ( !$ns || any { $ns eq $_ } ( SIGNON_1_1, SIGNON_1_0 ) );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
!$ns || &any(sub { $ns eq $_; } , 'http://openid.net/signon/1.1', 'http://openid.net/signon/1.0')
l!l&&r!l&&!r
000
MC/DC0%0/2
!$ns || &any(sub { $ns eq $_; } , 'http://openid.net/signon/1.1', 'http://openid.net/signon/1.0')
!$ns &any(sub { $ns eq $_; } , 'http://openid.net/signon/1.1', 'http://openid.net/signon/1.0')
Truth table0%0/3
not(A) || B
A= !$nsB= &any(sub { $ns eq $_; } , 'http://openid.net/signon/1.1', 'http://openid.net/signon/1.0')
ABresult
1X1
011
000
232 }
233  
234 0 ▶sub is_openid2 {
Subroutine is_openid2: not called CC=2 SCAR=17.9
Pod undocumented
235 0 my $self = shift;
236 0 my $ns = $self->get('ns');
237 0 ▶ return ( $ns && $ns eq SPEC_2_0 );
Condition0%0/3
$ns && $ns eq 'http://specs.openid.net/auth/2.0'
!ll&&!rl&&r
000
MC/DC0%0/2
$ns && $ns eq 'http://specs.openid.net/auth/2.0'
$ns $ns eq 'http://specs.openid.net/auth/2.0'
Truth table0%0/3
A && B
A= $nsB= $ns eq 'http://specs.openid.net/auth/2.0'
ABresult
0X0
100
111
238 }
239  
240 3 1;
« Lite/Util/URI.pm ↑ Summary Lite/Util/XRI.pm »