blib/lib/Gantry/Plugins/CookieCheck.pm

filter: Statementstmt 29.6% 16 / 54 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 19.6% 23 / 117 CC 18 SCAR 43.5
CC
18
Cov
17%
set_test_cookie
132.0
do_cookiecheck
56.0
get_callbacks
6.0
CRAP 77.5
↑ Summary
1 package Gantry::Plugins::CookieCheck;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Gantry::Utils::Crypt ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our @EXPORT = qw(
9 do_cookiecheck
10 );
11  
12 1 our $VERSION = '0.02';
13  
14 1 my %registered_callbacks;
15  
16 #-----------------------------------------------------------
17 # $class->get_callbacks( $namespace )
18 #-----------------------------------------------------------
19 0 ▶sub get_callbacks {
Subroutine get_callbacks: not called CC=2 SCAR=17.9
Pod documented
20 0 my ( $class, $namespace ) = @_;
21  
22 0 ▶ return if ( $registered_callbacks{ $namespace }++ );
Branch: 1 branch
BranchTrueFalseTotal
if $registered_callbacks{$namespace}++ 0 0 0
23  
24 return (
25 0 { phase => 'pre_init', callback => \&set_test_cookie },
26 );
27 }
28  
29 #-----------------------------------------------------------
30 # set_test_cookie
31 #-----------------------------------------------------------
32 0 ▶sub set_test_cookie {
Subroutine set_test_cookie: not called CC=11 SCAR=48.8
Pod documented
33 0 my ( $gobj ) = @_;
34 0 my $uri = $gobj->fish_uri();
35 0 my $loc = $gobj->fish_location();
36 0 my $cc_exclude = $gobj->fish_config('cc_exclude');
37  
38 # Set a test cookie under the following circumstances.
39 # The test cookie (acceptcookies) is not already set.
40 # The current uri does not match cookiecheck.
41 # There is no cookie check exclude path provided or
42 # there is an exclusion and it doesn't match the current location.
43 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $gobj->get_cookies("acceptcookies") || $uri =~ m[cookiecheck/?$]o and !$cc_exclude || $cc_exclude && !($uri =~ /$cc_exclude/)) 0 0 0
Condition0%0/12
not $gobj->get_cookies("acceptcookies") || $uri =~ m[cookiecheck/?$]o and !$cc_exclude || $cc_exclude && !($uri =~ /$cc_exclude/)
!ll&&!rl&&r
000
$gobj->get_cookies('acceptcookies') || $uri =~ m[cookiecheck/?$]o
l!l&&r!l&&!r
000
not $cc_exclude or $cc_exclude and not $uri =~ /$cc_exclude/
l!l&&r!l&&!r
000
$cc_exclude and not $uri =~ /$cc_exclude/
!ll&&!rl&&r
000
MC/DC0%0/5
not $gobj->get_cookies("acceptcookies") || $uri =~ m[cookiecheck/?$]o and !$cc_exclude || $cc_exclude && !($uri =~ /$cc_exclude/)
$gobj->get_cookies('acceptcookies') $uri =~ m[cookiecheck/?$]o not $cc_exclude $cc_exclude not $uri =~ /$cc_exclude/
Truth table0%0/6
not(A || B) and not(C) or D and not(E)
A= $gobj->get_cookies('acceptcookies')B= $uri =~ m[cookiecheck/?$]oC= not $cc_excludeD= $cc_excludeE= not $uri =~ /$cc_exclude/
ABCDEresult
1XXXX0
01XXX0
0000X0
000100
001XX1
000111
44 ( ! $gobj->get_cookies( 'acceptcookies' ) ) and
45 ( $uri !~ /cookiecheck\/?$/o ) and
46 (
47 ( ! $cc_exclude ) or ( $cc_exclude and ( $uri !~ /$cc_exclude/ ) )
48 )
49 ) {
50 0 my $req = $gobj->apache_request();
51 0 ▶ my $secret = $gobj->fish_config( 'cc_secret' )
Condition0%0/3
$gobj->fish_config('cc_secret') || $gobj->gantry_secret
l!l&&r!l&&!r
000
MC/DC0%0/2
$gobj->fish_config('cc_secret') || $gobj->gantry_secret
$gobj->fish_config('cc_secret') $gobj->gantry_secret
Truth table0%0/3
A || B
A= $gobj->fish_config('cc_secret')B= $gobj->gantry_secret
ABresult
1X1
011
000
52 || $gobj->gantry_secret();
53 0 my $crypt = Gantry::Utils::Crypt->new( { 'secret' => $secret } );
54 0 my $qstring = '';
55 0 my $goto;
56 my $cookie;
57
58 0 $cookie = {
59 name => 'acceptcookies',
60 value => '1',
61 path => '/',
62 };
63 0 ▶ $cookie->{domain} = $gobj->fish_config('cc_domain')
Branch: 1 branch
BranchTrueFalseTotal
if $gobj->fish_config("cc_domain") 0 0 0
64 if $gobj->fish_config('cc_domain');
65  
66 # Set a test cookie and then redirect.
67 0 $gobj->set_cookie($cookie);
68  
69 # Determine where to redirect the user for the cookie check.
70 0 $uri =~ s/^$loc//;
71 0 ▶ $goto = $uri || '/' ;
Condition0%0/2
$uri || '/'
l!l
00
MC/DC0%0/1
$uri || '/'
$uri
Truth table0%0/2
A
A= $uri
Aresult
11
00
72  
73 # Add parameters.
74 0 foreach my $param ( $req->param() ) {
75 0 $qstring .= sprintf( '&%s=%s', $param, $req->param( $param ) );
76 }
77  
78 0 ▶ if ( $qstring ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qstring) 0 0 0
79 # Change the first & to a ? and add query string to goto.
80 0 $qstring =~ s/^&/?/o;
81 0 $goto .= $qstring;
82 }
83  
84 # Encrypt goto
85 0 $goto = $gobj->url_encode( $crypt->encrypt( $goto ) );
86  
87 # Redirect the user.
88 0 $gobj->relocate( $loc . "/cookiecheck?url=${goto}" );
89 }
90 }
91  
92 #-----------------------------------------------------------
93 # do_cookiecheck()
94 #-----------------------------------------------------------
95 0 ▶sub do_cookiecheck {
Subroutine do_cookiecheck: not called CC=7 SCAR=40.3
Pod documented
96 0 my $gobj = shift;
97 0 my $params = $gobj->params();
98 0 ▶ my $secret = $gobj->fish_config( 'cc_secret' )
Condition0%0/3
$gobj->fish_config('cc_secret') || $gobj->gantry_secret
l!l&&r!l&&!r
000
MC/DC0%0/2
$gobj->fish_config('cc_secret') || $gobj->gantry_secret
$gobj->fish_config('cc_secret') $gobj->gantry_secret
Truth table0%0/3
A || B
A= $gobj->fish_config('cc_secret')B= $gobj->gantry_secret
ABresult
1X1
011
000
99 || $gobj->gantry_secret();
100 0 my $crypt = Gantry::Utils::Crypt->new( { 'secret' => $secret } );
101  
102 # Decrypt url parameter.
103 0 $params->{url} = $crypt->decrypt( $params->{url} );
104  
105 # If acceptcookies is set then send the user to the original
106 # url they requested.
107 0 ▶ if( $gobj->get_cookies( 'acceptcookies' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gobj->get_cookies('acceptcookies')) { } 0 0 0
108 0 $gobj->relocate( $gobj->location() . $params->{url} );
109 }
110 else {
111 # Cookies aren't enabled. Display an error page.
112 0 ▶ my $cc_title = $gobj->fish_config( 'cc_title' ) || 'Missing Cookies';
Condition0%0/2
$gobj->fish_config('cc_title') || 'Missing Cookies'
l!l
00
MC/DC0%0/1
$gobj->fish_config('cc_title') || 'Missing Cookies'
$gobj->fish_config('cc_title')
Truth table0%0/2
A
A= $gobj->fish_config('cc_title')
Aresult
11
00
113 0 ▶ my $cc_wrapper = $gobj->fish_config( 'cc_wrapper' ) ||
Condition0%0/5
$gobj->fish_config('cc_wrapper') || $gobj->fish_config('template_wrapper') || 'default.tt'
l!l
00
$gobj->fish_config("cc_wrapper") or $gobj->fish_config("template_wrapper")
l!l&&r!l&&!r
000
MC/DC0%0/2
$gobj->fish_config('cc_wrapper') || $gobj->fish_config('template_wrapper') || 'default.tt'
$gobj->fish_config("cc_wrapper") $gobj->fish_config("template_wrapper")
Truth table0%0/3
A or B
A= $gobj->fish_config("cc_wrapper")B= $gobj->fish_config("template_wrapper")
ABresult
1X1
011
000
114 $gobj->fish_config( 'template_wrapper' ) || 'default.tt';
115 0 ▶ my $cc_template = $gobj->fish_config( 'cc_template' ) || 'cc.tt';
Condition0%0/2
$gobj->fish_config('cc_template') || 'cc.tt'
l!l
00
MC/DC0%0/1
$gobj->fish_config('cc_template') || 'cc.tt'
$gobj->fish_config('cc_template')
Truth table0%0/2
A
A= $gobj->fish_config('cc_template')
Aresult
11
00
116  
117 0 $gobj->template_wrapper( $cc_wrapper );
118 0 $gobj->stash->view->title( $cc_title );
119 0 $gobj->stash->view->template( $cc_template );
120 }
121 }
122  
123 1 1;
124  
125 __END__
↑ Summary