Lite/RelyingParty/Discover/Service.pm

filter: Statementstmt 48.8% 41 / 84 Branchbran 18.1% 4 / 22 Conditioncond 62.5% 5 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 48.0% 12 / 25 Podpod 76.9% 10 / 13 totaltotal 46.5% 73 / 157 CC 19 SCAR 24.5
CC
19
Cov
44%
copy
42.0
display_identifier
30.0
preferred_namespace
6.0
CRAP 11.6
« Lite/Provider/AssociationBuilder.pm ↑ Summary Lite/Realm.pm »
1 package OpenID::Lite::RelyingParty::Discover::Service;
2  
3 4 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 use OpenID::Lite::Constants::Namespace
5 4 ▶ qw(SERVER_2_0 SPEC_2_0 SPEC_1_0 SIGNON_2_0 SIGNON_1_1 SIGNON_1_0);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use List::MoreUtils qw(any none);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 has 'uris' => (
10 is => 'ro',
11 isa => 'ArrayRef',
12 10 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 4 );
14  
15 has 'types' => (
16 is => 'ro',
17 isa => 'ArrayRef',
18 10 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 4 );
20  
21 4 has 'claimed_identifier' => (
22 is => 'rw',
23 isa => 'Str',
24 );
25  
26 4 has 'op_local_identifier' => (
27 is => 'rw',
28 isa => 'Str',
29 );
30  
31 4 my @PRIORITY_ORDER = ( SERVER_2_0, SIGNON_2_0, SIGNON_1_1, SIGNON_1_0 );
32  
33 has 'type_priority' => (
34 is => 'rw',
35 isa => 'Int',
36 10 ▶ default => sub {$#PRIORITY_ORDER}
Subroutine __ANON__: called CC=1 SCAR=0.0
37 4 );
38  
39 4 has '_display_identifier' => (
40 is => 'rw',
41 isa => 'Str',
42 );
43  
44 0 ▶sub copy {
Subroutine copy: not called CC=6 SCAR=37.4
Pod documented
45 0 my $self = shift;
46 0 my $class = ref($self);
47 0 my $copied = $class->new;
48 0 my $uris = $self->uris;
49 0 $copied->add_uri($_) for @$uris;
50 0 my $types = $self->types;
51 0 $copied->add_type($_) for @$types;
52 0 ▶ $copied->claimed_identifier( $self->claimed_identifier )
Branch: 1 branch
BranchTrueFalseTotal
if $self->claimed_identifier 0 0 0
53 if $self->claimed_identifier;
54 0 ▶ $copied->op_local_identifier( $self->op_local_identifier )
Branch: 1 branch
BranchTrueFalseTotal
if $self->op_local_identifier 0 0 0
55 if $self->op_local_identifier;
56 0 ▶ $copied->_display_identifier( $self->_display_identifier )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_display_identifier 0 0 0
57 if $self->_display_identifier;
58 0 return $copied;
59 }
60  
61 0 ▶sub display_identifier {
Subroutine display_identifier: not called CC=5 SCAR=34.0
Pod undocumented
62 0 my $self = shift;
63 0 my $dispid = shift;
64 0 ▶ if ($dispid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dispid) { } 0 0 0
65 0 $self->_display_identifier($dispid);
66 } else {
67 0 ▶ return $self->_display_identifier if $self->_display_identifier;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_display_identifier 0 0 0
68 0 ▶ return unless $self->claimed_identifier;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->claimed_identifier 0 0 0
69 0 my $parsed_id = URI->new($self->claimed_identifier);
70 0 ▶ return $self->claimed_identifier if not $parsed_id->fragment;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed_id->fragment 0 0 0
71 0 $parsed_id->fragment(undef);
72 0 return $parsed_id->as_string;
73 }
74 }
75  
76 10 ▶sub find_local_identifier {
Subroutine find_local_identifier: called CC=2 SCAR=7.1
Pod documented
77 10 my $self = shift;
78 10 ▶ return $self->op_local_identifier || $self->claimed_identifier;
Condition66%2/3
$self->op_local_identifier || $self->claimed_identifier
l!l&&r!l&&!r
820
MC/DC0%0/2
$self->op_local_identifier || $self->claimed_identifier
$self->op_local_identifier $self->claimed_identifier
Truth table66%2/3
A || B
A= $self->op_local_identifierB= $self->claimed_identifier
ABresult
1X1
011
000
79 }
80  
81 10 ▶sub url {
Subroutine url: called CC=2 SCAR=7.1
Pod documented
82 10 my $self = shift;
83 10 my $uris = $self->uris;
84 10 ▶ return $uris->[0] || '';
Condition50%1/2
$uris->[0] || ''
l!l
100
MC/DC0%0/1
$uris->[0] || ''
$uris->[0]
Truth table50%1/2
A
A= $uris->[0]
Aresult
11
00
85 }
86  
87 0 ▶sub is_op_identifier {
Subroutine is_op_identifier: not called CC=1 SCAR=6.9
Pod documented
88 0 my $self = shift;
89 0 my $types = $self->types;
90 0 ▶ return ( any { $_ eq SERVER_2_0 } @$types );
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 }
92  
93 0 ▶sub preferred_namespace {
Subroutine preferred_namespace: not called CC=2 SCAR=17.9
Pod documented
94 0 my $self = shift;
95 0 ▶ $self->requires_compatibility_mode ? SPEC_1_0 : SPEC_2_0;
Branch: 1 branch
BranchTrueFalseTotal
$self->requires_compatibility_mode ? : 0 0 0
96 }
97  
98 0 ▶sub requires_compatibility_mode {
Subroutine requires_compatibility_mode: not called CC=1 SCAR=6.9
Pod documented
99 0 my $self = shift;
100 0 my $types = $self->types;
101 0 ▶ return ( none { $_ eq SERVER_2_0 || $_ eq SIGNON_2_0 } @$types );
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "http://specs.openid.net/auth/2.0/server" or $_ eq "http://specs.openid.net/auth/2.0/signon" 0 0 0
102 }
103  
104 0 ▶sub has_uri {
Subroutine has_uri: not called CC=1 SCAR=6.9
Pod documented
105 0 my ( $self, $uri ) = @_;
106 0 ▶ return ( any { $_ eq $uri } @{ $self->uris } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 }
108  
109 10 ▶sub add_uri {
Subroutine add_uri: called CC=1 SCAR=0.0
Pod documented
110 10 my ( $self, $uri ) = @_;
111 10 my $uris = $self->uris;
112 10 push @$uris, $uri;
113 }
114  
115 0 ▶sub add_uris {
Subroutine add_uris: not called CC=2 SCAR=17.9
Pod undocumented
116 0 my $self = shift;
117 0 $self->add_uri($_) for @_;
118 }
119  
120 10 ▶sub add_type {
Subroutine add_type: called CC=4 SCAR=13.9
Pod documented
121 10 my ( $self, $type ) = @_;
122 10 my $types = $self->types;
123 10 ▶ for ( my $i = 0; $i < @PRIORITY_ORDER; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @PRIORITY_ORDER) 40 10 50
124 40 ▶ if ( $type eq $PRIORITY_ORDER[$i]
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $PRIORITY_ORDER[$i] and $self->type_priority > $i) 10 30 40
Condition66%2/3
$type eq $PRIORITY_ORDER[$i] and $self->type_priority > $i
!ll&&!rl&&r
30010
MC/DC50%1/2
$type eq $PRIORITY_ORDER[$i] and $self->type_priority > $i
$type eq $PRIORITY_ORDER[$i] $self->type_priority > $i
Truth table66%2/3
A and B
A= $type eq $PRIORITY_ORDER[$i]B= $self->type_priority > $i
ABresult
0X0
100
111
125 && $self->type_priority > $i )
126 {
127 10 $self->type_priority($i);
128 }
129 }
130 10 push @$types, $type;
131 }
132  
133 0 ▶sub add_types {
Subroutine add_types: not called CC=2 SCAR=17.9
Pod undocumented
134 0 my $self = shift;
135 0 $self->add_type($_) for @_;
136 }
137  
138 0 ▶sub has_type {
Subroutine has_type: not called CC=1 SCAR=6.9
Pod documented
139 0 my ( $self, $type ) = @_;
140 0 ▶ return ( any { $_ eq $type } @{ $self->types } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 }
142  
143 4 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 4 __PACKAGE__->meta->make_immutable;
145 4 1;
146  
147 =head1 NAME
148  
149 OpenID::Lite::Relyingparty::Discover::Service - Discovered information
150  
151 =head1 SYNOPSIS
152  
153 $service->url;
154 $service->claimed_identifier
155 $service->op_local_identifier
156 $service->copy;
157 $service->find_local_identifier;
158 $service->is_op_identifier;
159 $service->preferred_namespace;
160 $service->requires_compatibility_mode;
161 $service->has_type( );
162 $service->add_type();
163 $service->has_uri();
164 $service->add_uri();
165  
166 =head1 DESCRIPTION
167  
168 This class's object represents discovered information.
169  
170 =head1 METHODS
171  
172 =head2 new
173  
174 my $service = OpenID::Lite::RelyingParty::Discover::Service->new;
175  
176 =head2 url
177  
178 Returns service endpoint url.
179  
180 my $service_endpoint_url = $service->url;
181  
182 =head2 add_type
183  
184 Add a type of service the OP provides.
185  
186 use OpenID::Lite::Constants::Namespace qw( SERVER_2_0 SIGNON_2_0 );
187  
188 $service->add_type( SERVER_2_0 );
189 $service->add_type( SIGNON_2_0 );
190  
191 =head2 has_type
192  
193 Check if the OP provides indicated type of service.
194  
195 use OpenID::Lite::Constants::Namespace qw( SERVER_2_0 );
196 $service->has_type( SERVER_2_0 );
197  
198 =head2 add_uri
199  
200 Add endpoint uri
201  
202 $service->has_uri(q{http://yourapp.com/openid/endpoint});
203  
204 =head2 has_uri
205  
206 Check if the service includes indicated uri.
207  
208 if ( $service->has_uri( $endpoint_uri ) ) {
209 ...
210 }
211  
212 =head2 claimed_identifier
213  
214 Return claimed identitifier if it has.
215 (When discovery is carried out with claimed_id)
216  
217 my $claimed_id = $service->claimed_identifier;
218  
219 =head2 op_local_identifier
220  
221 Return op local identitifier if it has.
222 (When discovery is carried out with claimed_id and the response which OP returns includes LocalID)
223  
224 my $op_local_identifier = $service->op_local_identifier;
225  
226 =head2 find_local_identifier
227  
228 Returns op_local_identfier if it found.
229 Or return claimed id.
230  
231 my $identity = $service->find_local_identifier;
232  
233  
234 =head2 copy
235  
236 my $copied_service = $service->copy();
237  
238 =head2 is_op_identifier
239  
240 Return true if this is for OP identifier
241 (When discovery is carried out with OP identifier)
242  
243 if ( $service->is_op_identifier ) {
244 ...
245 }
246  
247 =head2 preferred_namespace
248  
249 Return proper namespace for openid.ns
250  
251 =head2 requires_compatibility_mode
252  
253 If the endpoint accepts only OpenID 1.x version protocol,
254 return true.
255  
256 =head1 AUTHOR
257  
258 Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
259  
260 =head1 COPYRIGHT AND LICENSE
261  
262 Copyright (C) 2009 by Lyo Kato
263  
264 This library is free software; you can redistribute it and/or modify
265 it under the same terms as Perl itself, either Perl version 5.8.8 or,
266 at your option, any later version of Perl 5 you may have available.
267  
268 =cut
« Lite/Provider/AssociationBuilder.pm ↑ Summary Lite/Realm.pm »