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 0.028;
2             our $AUTHORITY = 'cpan:STEVAN';
3              
4 1     1   771 use Types::Standard qw(Str ArrayRef);
  1         3  
  1         13  
5              
6 1     1   789 use Moo::Role;
  1         3  
  1         12  
7              
8             with(
9             'HTTP::Throwable',
10             'HTTP::Throwable::Role::BoringText',
11             );
12              
13 4     4 0 207 sub default_status_code { 401 }
14 4     4 0 18295 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   532 no Moo::Role; 1;
  1         3  
  1         33  
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.028
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 PERL VERSION
64              
65             This library should run on perls released even a long time ago. It should work
66             on any version of perl released in the last five years.
67              
68             Although it may work on older versions of perl, no guarantee is made that the
69             minimum required version will not be increased. The version may be increased
70             for any reason, and there is no promise that patches will be accepted to lower
71             the minimum required perl.
72              
73             =head1 ATTRIBUTES
74              
75             =head2 www_authenticate
76              
77             This is a required string or array of string that will be used to populate
78             the 'WWW-Authenticate' header(s) when creating a PSGI response.
79              
80             =head1 SEE ALSO
81              
82             HTTP Authentication: Basic and Digest Access Authentication - L
83              
84             WWW-Authenticate Header - L
85              
86             =head1 AUTHORS
87              
88             =over 4
89              
90             =item *
91              
92             Stevan Little
93              
94             =item *
95              
96             Ricardo Signes
97              
98             =back
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             This software is copyright (c) 2011 by Infinity Interactive, Inc.
103              
104             This is free software; you can redistribute it and/or modify it under
105             the same terms as the Perl 5 programming language system itself.
106              
107             =cut
108              
109             __END__