File Coverage

blib/lib/OpenID/Lite/Message/Decoder.pm
Criterion Covered Total %
statement 9 23 39.1
branch 0 8 0.0
condition n/a
subroutine 3 6 50.0
pod 0 3 0.0
total 12 40 30.0


line stmt bran cond sub pod time code
1             package OpenID::Lite::Message::Decoder;
2              
3 3     3   2085 use Any::Moose;
  3         76530  
  3         40  
4 3     3   5423 use UNIVERSAL::require;
  3         5941  
  3         32  
5              
6             with 'OpenID::Lite::Role::ErrorHandler';
7              
8             my %DECODERS;
9             my %CLASS_PAIRS = (
10             'HASH' => 'OpenID::Lite::Message::Decoder::Hash',
11             'CGI' => 'OpenID::Lite::Message::Decoder::CGI',
12             'Apache::Request' => 'OpenID::Lite::Message::Decoder::CGI',
13             'Apache2::Request' => 'OpenID::Lite::Message::Decoder::CGI',
14             'Catalyst::Request' => 'OpenID::Lite::Message::Decoder::CGI',
15             'HTTP::Engine::Request' => 'OpenID::Lite::Message::Decoder::CGI',
16             'Plack::Request' => 'OpenID::Lite::Message::Decoder::CGI',
17             'Apache' => 'OpenID::Lite::Message::Decoder::Apache',
18             'Mojo::Message::Request' => 'OpenID::Lite::Message::Decoder::Mojo',
19             );
20              
21             sub add_pair {
22 0     0 0   my ( $class, $request_class, $decoder_class ) = @_;
23 0           $CLASS_PAIRS{ $request_class } = $decoder_class;
24             }
25              
26             sub decode {
27 0     0 0   my ( $self, $request ) = @_;
28 0           my $req_class = ref $request;
29 0           my $decoder = $self->create_decoder_for($req_class);
30 0 0         return unless $decoder;
31             #or return $self->ERROR(
32             # sprintf q{Proper decoder not found for request class "%s"},
33             # $req_class );
34 0           return $decoder->decode($request);
35             }
36              
37             sub create_decoder_for {
38 0     0 0   my ( $self, $req_class ) = @_;
39 0 0         return unless exists $CLASS_PAIRS{$req_class};
40 0           my $decoder_class = $CLASS_PAIRS{$req_class};
41 0 0         unless ( exists $DECODERS{$decoder_class} ) {
42 0 0         $decoder_class->require or return;
43 0           $DECODERS{$decoder_class} = $decoder_class->new;
44             }
45 0           return $DECODERS{$decoder_class};
46             }
47              
48 3     3   664 no Any::Moose;
  3         4  
  3         31  
49             __PACKAGE__->meta->make_immutable;
50             1;
51