File Coverage

blib/lib/OpenID/Login/Discover.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 10 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 1 1 100.0
total 37 44 84.0


line stmt bran cond sub pod time code
1             package OpenID::Login::Discover;
2             {
3             $OpenID::Login::Discover::VERSION = '0.1.2';
4             }
5              
6             # ABSTRACT: Find an endpoint for generic OpenID identifiers
7              
8 4     4   25 use Moose;
  4         8  
  4         58  
9              
10             has claimed_id => (
11             is => 'rw',
12             isa => 'Str',
13             required => 1,
14             );
15              
16             has ua => (
17             is => 'rw',
18             isa => 'LWP::UserAgent',
19             required => 1,
20             );
21              
22              
23             sub perform_discovery {
24 5     5 1 10 my $self = shift;
25              
26 5         192 my $claimed_id = $self->claimed_id;
27 5   33     28 my $server = $self->_get_xrds_location($claimed_id) || $self->claimed_id;
28 5         10 my $open_id_endpoint;
29 5 50       15 if ($server) {
30 5         12 my $xrds = $self->_get($server)->decoded_content;
31 5 50       30363 if ( $xrds =~ m{<URI>([^<>]+)</URI>} ) {
32 5         16 $open_id_endpoint = $1;
33             }
34             }
35              
36 5         218 return $open_id_endpoint;
37             }
38              
39             sub _get {
40 10     10   21 my ( $self, $url ) = @_;
41              
42 10         411 my $ua = $self->ua;
43 10         40 my $res = $ua->get($url);
44 10 50       11172 $res->is_success or return;
45 10         116 $res;
46             }
47              
48             sub _get_xrds_location {
49 5     5   11 my ( $self, $entry_point ) = @_;
50              
51 5         18 my $res = $self->_get( $entry_point, Accept => 'application/xrds+xml' );
52 5 50       16 return unless $res;
53 5 50       28 my $xrds_location = $res->header('X-XRDS-Location') or return;
54 5         226 return $xrds_location;
55             }
56              
57 4     4   29500 no Moose;
  4         12  
  4         27  
58             __PACKAGE__->meta->make_immutable;
59             1;
60              
61              
62              
63             =pod
64              
65             =head1 NAME
66              
67             OpenID::Login::Discover - Find an endpoint for generic OpenID identifiers
68              
69             =head1 VERSION
70              
71             version 0.1.2
72              
73             =head1 METHODS
74              
75             =head2 perform_discovery
76              
77             Performs OpenID endpoint discovery for generic OpenID indentifiers
78              
79             =head1 AUTHOR
80              
81             Holger Eiboeck <realholgi@cpan.org>
82              
83             =head1 COPYRIGHT AND LICENSE
84              
85             This software is copyright (c) 2013 by Holger Eiboeck.
86              
87             This is free software; you can redistribute it and/or modify it under
88             the same terms as the Perl 5 programming language system itself.
89              
90             =cut
91              
92              
93             __END__
94              
95