File Coverage

blib/lib/Net/HTTP/Spore/Middleware/Auth/Basic.pm
Criterion Covered Total %
statement 10 10 100.0
branch 2 4 50.0
condition 1 3 33.3
subroutine 3 3 100.0
pod 0 1 0.0
total 16 21 76.1


line stmt bran cond sub pod time code
1             package Net::HTTP::Spore::Middleware::Auth::Basic;
2             $Net::HTTP::Spore::Middleware::Auth::Basic::VERSION = '0.07';
3             # ABSTRACT: middleware for Basic authentication
4              
5 1     1   822 use Moose;
  1         5  
  1         10  
6             extends 'Net::HTTP::Spore::Middleware::Auth';
7              
8 1     1   7335 use MIME::Base64;
  1         3  
  1         183  
9              
10             has username => (isa => 'Str', is => 'rw', predicate => 'has_username');
11             has password => (isa => 'Str', is => 'rw', predicate => 'has_password');
12              
13             sub call {
14 1     1 0 4 my ( $self, $req ) = @_;
15              
16 1 50       10 return unless $self->should_authenticate($req);
17              
18 1 50 33     57 if ( $self->has_username && $self->has_password ) {
19 1         52 $req->header(
20             'Authorization' => 'Basic '
21             . MIME::Base64::encode(
22             $self->username . ':' . $self->password, ''
23             )
24             );
25             }
26             }
27              
28             1;
29              
30             __END__
31              
32             =pod
33              
34             =encoding UTF-8
35              
36             =head1 NAME
37              
38             Net::HTTP::Spore::Middleware::Auth::Basic - middleware for Basic authentication
39              
40             =head1 VERSION
41              
42             version 0.07
43              
44             =head1 SYNOPSIS
45              
46             my $client = Net::HTTP::Spore->new_from_spec('github.json');
47             $client->enable('Auth::Basic', username => 'xxx', password => 'yyy');
48              
49             =head1 DESCRIPTION
50              
51             Net::HTTP::Spore::Middleware::Auth::Basic is a middleware to handle Basic authentication mechanism.
52              
53             =head1 AUTHORS
54              
55             =over 4
56              
57             =item *
58              
59             Franck Cuny <franck.cuny@gmail.com>
60              
61             =item *
62              
63             Ash Berlin <ash@cpan.org>
64              
65             =item *
66              
67             Ahmad Fatoum <athreef@cpan.org>
68              
69             =back
70              
71             =head1 COPYRIGHT AND LICENSE
72              
73             This software is copyright (c) 2012 by Linkfluence.
74              
75             This is free software; you can redistribute it and/or modify it under
76             the same terms as the Perl 5 programming language system itself.
77              
78             =cut