File Coverage

blib/lib/OpenID/Lite/RelyingParty/Discover/Parser/XRDS.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package OpenID::Lite::RelyingParty::Discover::Parser::XRDS;
2              
3 1     1   8 use Any::Moose;
  1         2  
  1         6  
4             with 'OpenID::Lite::Role::Parser';
5             with 'OpenID::Lite::Role::ErrorHandler';
6              
7 1     1   1065 use XML::LibXML;
  0            
  0            
8             use OpenID::Lite::RelyingParty::Discover::Service::Builder;
9              
10             sub parse {
11             my ( $self, $result ) = @_;
12              
13             my $identifier = $result->normalized_identifier;
14             my $parser = XML::LibXML->new;
15             my $doc;
16             eval { $doc = $parser->parse_string( $result->content ); };
17             if ($@) {
18             return $self->ERROR( sprintf q{Failed to parse xrds "%s"}, $@ );
19             }
20              
21             my @xrd
22             = $doc->findnodes(q{*[local-name()='XRDS']/*[local-name()='XRD']});
23             return $self->ERROR( sprintf q{XRD element not found for iname "%s".},
24             $identifier )
25             unless @xrd > 0;
26              
27             my $xrd = $xrd[0];
28              
29             my $builder = OpenID::Lite::RelyingParty::Discover::Service::Builder->new(
30             claimed_identifier => $identifier, );
31             my $services = $builder->build_services($xrd);
32             return $self->ERROR(q{No service found.}) unless @$services > 0;
33             return $services;
34             }
35              
36             no Any::Moose;
37             __PACKAGE__->meta->make_immutable;
38             1;
39