Lite/RelyingParty/Discover/Parser/HTML.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 98.2% 57 / 58 CC 6 SCAR 8.7
CC
6
Cov
100%
parse
4.0
_extract
3.0
BEGIN
1.0
CRAP 2.4
« Lite/RelyingParty/Associator/ParamBuilder.pm ↑ Summary Lite/SignatureMethod.pm »
1 package OpenID::Lite::RelyingParty::Discover::Parser::HTML;
2  
3 3 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 with 'OpenID::Lite::Role::Parser';
5 3 with 'OpenID::Lite::Role::ErrorHandler';
6  
7 3 ▶use OpenID::Lite::RelyingParty::Discover::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use OpenID::Lite::Constants::Namespace qw(SIGNON_2_0 SIGNON_1_1);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use HTML::TreeBuilder::XPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶sub parse {
Subroutine parse: called CC=4 SCAR=13.9
Pod undocumented
12 10 my ( $self, $result ) = @_;
13  
14 10 my $rels = [
15 { namespace => SIGNON_2_0,
16 endpoint_rel => q{openid2.provider},
17 local_id_rel => q{openid2.local_id},
18 },
19 { namespace => SIGNON_1_1,
20 endpoint_rel => q{openid.server},
21 local_id_rel => q{openid.delegate},
22  
23 },
24 ];
25  
26 10 my $tree = HTML::TreeBuilder::XPath->new;
27 10 $tree->parse( lc $result->content );
28  
29 10 my $services = [];
30 10 for my $rel (@$rels) {
31 20 my $service = $self->_extract( $tree, $rel );
32 20 ▶ if ($service) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service) 10 10 20
33 10 $service->claimed_identifier( $result->normalized_identifier );
34 10 push @$services, $service;
35 }
36 }
37  
38 10 ▶ return $self->ERROR(
Branch: 1 branch
BranchTrueFalseTotal
unless @$services > 0 2 8 10
39 q{Couldn't extract provider information for OpenID protocol})
40 unless @$services > 0;
41  
42 8 return $services;
43  
44 }
45  
46 20 ▶sub _extract {
Subroutine _extract: called CC=3 SCAR=11.0
47 20 my ( $self, $tree, $rel ) = @_;
48 my $op_endpoint_url
49 20 ▶ = $tree->findvalue( $self->_build_xpath_with( $rel->{endpoint_rel} ) )
Branch: 1 branch
BranchTrueFalseTotal
my $op_endpoint_url = $tree->findvalue($self->_build_xpath_with($rel->{"endpoint_rel"})) or return 10 10 20
50 or return;
51  
52 10 my $service = OpenID::Lite::RelyingParty::Discover::Service->new;
53 10 $service->add_uri($op_endpoint_url);
54 10 $service->add_type( $rel->{namespace} );
55 my $local_id
56 10 = $tree->findvalue( $self->_build_xpath_with( $rel->{local_id_rel} ) );
57 10 ▶ $service->op_local_identifier($local_id) if $local_id;
Branch: 1 branch
BranchTrueFalseTotal
if $local_id 8 2 10
58 10 return $service;
59 }
60  
61 30 ▶sub _build_xpath_with {
Subroutine _build_xpath_with: called CC=1 SCAR=0.0
62 30 my ( $self, $rel ) = @_;
63 30 return sprintf(q{/html/head/link[@rel="%s"][1]/@href}, $rel);
64 }
65  
66 3 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 3 __PACKAGE__->meta->make_immutable;
68 3 1;
69  
« Lite/RelyingParty/Associator/ParamBuilder.pm ↑ Summary Lite/SignatureMethod.pm »