examples/yapc-talk-examples/020-auth.psgi

filter: Statementstmt 100% 29 / 29 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 95.8% 46 / 48 CC 4 SCAR 6.6
CC
4
Cov
97%
is_authorized
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« blib/lib/Web/Machine/Resource.pm ↑ Summary blib/lib/Web/Machine/Util/ContentNegotiation.pm »
1 #!perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Web::Machine;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =pod
9  
10 =cut
11  
12 {
13 package YAPC::NA::2012::Example020::Resource;
14 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use Web::Machine::Util qw[ create_header ];
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶ use parent 'Web::Machine::Resource';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶ sub content_types_provided { [ { 'text/html' => 'to_html' } ] }
Subroutine content_types_provided: called CC=1 SCAR=0.0
21  
22 1 ▶ sub to_html { '<html><body><h1>Hello World</h1></body></html>' }
Subroutine to_html: called CC=1 SCAR=0.0
23  
24 3 ▶ sub is_authorized {
Subroutine is_authorized: called CC=4 SCAR=13.9
25 3 my ($self, $auth_header) = @_;
26 3 ▶ if ( $auth_header ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_header) 2 1 3
27 2 ▶ return 1 if $auth_header->username eq 'foo' && $auth_header->password eq 'bar';
Branch: 1 branch
BranchTrueFalseTotal
if $auth_header->username eq "foo" and $auth_header->password eq "bar" 1 1 2
Condition66%2/3
$auth_header->username eq "foo" and $auth_header->password eq "bar"
!ll&&!rl&&r
011
MC/DC50%1/2
$auth_header->username eq "foo" and $auth_header->password eq "bar"
$auth_header->username eq "foo" $auth_header->password eq "bar"
Truth table66%2/3
A and B
A= $auth_header->username eq "foo"B= $auth_header->password eq "bar"
ABresult
0X0
100
111
28 }
29 2 return create_header( 'WWWAuthenticate' => [ 'Basic' => ( realm => 'Webmachine' ) ] );
30 }
31  
32 }
33  
34 1 Web::Machine->new( resource => 'YAPC::NA::2012::Example020::Resource' )->to_app;
« blib/lib/Web/Machine/Resource.pm ↑ Summary blib/lib/Web/Machine/Util/ContentNegotiation.pm »