File Coverage

blib/lib/OpenID/Lite/RelyingParty/Discover/Fetcher/Yadis.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 8 0.0
condition 0 9 0.0
subroutine 4 8 50.0
pod 0 1 0.0
total 16 62 25.8


line stmt bran cond sub pod time code
1             package OpenID::Lite::RelyingParty::Discover::Fetcher::Yadis;
2              
3 1     1   6 use Any::Moose;
  1         2  
  1         5  
4             with 'OpenID::Lite::Role::AgentHandler';
5             with 'OpenID::Lite::Role::ErrorHandler';
6              
7 1     1   1262 use OpenID::Lite::RelyingParty::Discover::Fetcher::Yadis::HTMLExtractor;
  1         4  
  1         18  
8 1     1   26 use OpenID::Lite::RelyingParty::Discover::FetchResult;
  1         2  
  1         8  
9             use OpenID::Lite::Constants::Yadis
10 1     1   27 qw(XRDS_HEADER YADIS_HEADER XRDS_CONTENT_TYPE);
  1         2  
  1         523  
11              
12             sub fetch {
13 0     0 0   my ( $self, $uri ) = @_;
14              
15 0           my $res = $self->agent->get( $uri, 'Accept' => XRDS_CONTENT_TYPE );
16 0 0         return $self->ERROR( sprintf q{Failed Yadis discovery on "%s"}, $uri )
17             unless $res->is_success;
18              
19 0           my $result = OpenID::Lite::RelyingParty::Discover::FetchResult->new;
20 0           $result->normalized_identifier($uri);
21              
22 0           my $content_type = $res->header('Content-Type');
23 0           my $xrds_type = quotemeta XRDS_CONTENT_TYPE;
24 0 0 0       if ( $content_type && $content_type =~ /^$xrds_type/i ) {
25 0           $result->content_type( lc $content_type );
26 0           $result->final_url( $res->base->as_string );
27 0           $result->content( $res->content );
28             }
29             else {
30              
31 0 0         my $yadis_location = $self->_extract_location($res)
32             or return $self->ERROR(
33             sprintf q{Failed Yadis discovery for url "%s"}, $uri );
34              
35 0           $res = $self->agent->get($yadis_location);
36 0 0         return $self->ERROR( sprintf q{Failed Yadis discovery for url "%s"},
37             $yadis_location )
38             unless $res->is_success;
39              
40 0           $result->content_type( lc $res->header('Content-Type') );
41 0           $result->final_url( $res->base->as_string );
42 0           $result->content( $res->content );
43             }
44 0           return $result;
45             }
46              
47             sub _extract_location {
48 0     0     my ( $self, $res ) = @_;
49 0   0       return $self->_extract_location_from_header($res)
50             || $self->_extract_location_from_html( $res->content );
51             }
52              
53             sub _extract_location_from_header {
54 0     0     my ( $self, $res ) = @_;
55 0   0       return $res->header(XRDS_HEADER)
56             || $res->header(YADIS_HEADER);
57             }
58              
59             sub _extract_location_from_html {
60 0     0     my ( $self, $content ) = @_;
61             return
62 0           OpenID::Lite::RelyingParty::Discover::Fetcher::Yadis::HTMLExtractor->extract($content);
63             }
64              
65             1;
66