File Coverage

blib/lib/HTTP/Throwable/Role/Status/Unauthorized.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 16 18 88.8


line stmt bran cond sub pod time code
1             package HTTP::Throwable::Role::Status::Unauthorized;
2             our $AUTHORITY = 'cpan:STEVAN';
3             $HTTP::Throwable::Role::Status::Unauthorized::VERSION = '0.026';
4 1     1   848 use Types::Standard qw(Str ArrayRef);
  1         2  
  1         10  
5              
6 1     1   626 use Moo::Role;
  1         2  
  1         8  
7              
8             with(
9             'HTTP::Throwable',
10             'HTTP::Throwable::Role::BoringText',
11             );
12              
13 4     4 0 168 sub default_status_code { 401 }
14 4     4 0 16347 sub default_reason { 'Unauthorized' }
15              
16             has 'www_authenticate' => (
17             is => 'ro',
18             isa => Str | ArrayRef[Str],
19             required => 1,
20             );
21              
22             around 'build_headers' => sub {
23             my $next = shift;
24             my $self = shift;
25             my $headers = $self->$next( @_ );
26             my $www_auth = $self->www_authenticate;
27             if ( ref $www_auth ) {
28             push @$headers => (map { ('WWW-Authenticate' => $_) } @$www_auth);
29             }
30             else {
31             push @$headers => ('WWW-Authenticate' => $www_auth );
32             }
33             $headers;
34             };
35              
36 1     1   494 no Moo::Role; 1;
  1         2  
  1         5  
37              
38             =pod
39              
40             =encoding UTF-8
41              
42             =head1 NAME
43              
44             HTTP::Throwable::Role::Status::Unauthorized - 401 Unauthorized
45              
46             =head1 VERSION
47              
48             version 0.026
49              
50             =head1 DESCRIPTION
51              
52             The request requires user authentication. The response MUST include a
53             WWW-Authenticate header field containing a challenge applicable to the
54             requested resource. The client MAY repeat the request with a suitable
55             Authorization header field. If the request already included Authorization
56             credentials, then the 401 response indicates that authorization has been
57             refused for those credentials. If the 401 response contains the same
58             challenge as the prior response, and the user agent has already attempted
59             authentication at least once, then the user SHOULD be presented the entity
60             that was given in the response, since that entity might include relevant
61             diagnostic information.
62              
63             =head1 ATTRIBUTES
64              
65             =head2 www_authenticate
66              
67             This is a required string or array of string that will be used to populate
68             the 'WWW-Authenticate' header(s) when creating a PSGI response.
69              
70             =head1 SEE ALSO
71              
72             HTTP Authentication: Basic and Digest Access Authentication - L
73              
74             WWW-Authenticate Header - L
75              
76             =head1 AUTHORS
77              
78             =over 4
79              
80             =item *
81              
82             Stevan Little
83              
84             =item *
85              
86             Ricardo Signes
87              
88             =back
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is copyright (c) 2011 by Infinity Interactive, Inc..
93              
94             This is free software; you can redistribute it and/or modify it under
95             the same terms as the Perl 5 programming language system itself.
96              
97             =cut
98              
99             __END__