File Coverage

blib/lib/OpenID/Lite/RelyingParty/Discover/Fetcher/XRI.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::Fetcher::XRI;
2              
3 1     1   7 use Any::Moose;
  1         2  
  1         5  
4             with 'OpenID::Lite::Role::ErrorHandler';
5             with 'OpenID::Lite::Role::AgentHandler';
6              
7             has 'proxy_url' => (
8             is => 'rw',
9             isa => 'Str',
10             );
11              
12 1     1   928 use XRI::Resolution::Lite;
  0            
  0            
13             use OpenID::Lite::RelyingParty::Discover::FetchResult;
14             use OpenID::Lite::Constants::Yadis qw(XRDS_CONTENT_TYPE);
15              
16             sub fetch {
17             my ( $self, $iname, $option ) = @_;
18             my %params;
19             $params{ua} = $self->agent if $self->agent;
20             $params{resolver} = $self->proxy_url if $self->proxy_url;
21             my $r = XRI::Resolution::Lite->new( {%params} );
22             my $xrds;
23             eval {
24             #XXX: XRI::Resolution::Lite handle type wrongly?
25             # Accept Header shouldn't be 'type' but 'format'.
26             $xrds = $r->resolve( $iname,
27             { format => XRDS_CONTENT_TYPE, type => $option->{service_type} } );
28             };
29             if ($@) {
30             return $self->ERROR( sprintf q{Failed to resolve XRI iname "%s": %s},
31             $iname, $@ );
32             }
33             my $result = OpenID::Lite::RelyingParty::Discover::FetchResult->new;
34             $result->content_type( XRDS_CONTENT_TYPE );
35             $result->normalized_identifier($iname);
36             $result->xrds($xrds);
37             return $result;
38             }
39              
40             no Any::Moose;
41             __PACKAGE__->meta->make_immutable;
42             1;
43