blib/lib/Plack/Middleware/XFrameOptions/All.pm

filter: Statementstmt 62.9% 17 / 27 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 2 / 2 totaltotal 56.8% 25 / 44 CC 4 SCAR 15.4
CC
4
Cov
52%
__ANON__
12.0
prepare_app
6.0
call
2.0
CRAP 4.7
↑ Summary
1 # ABSTRACT: Plack middleware to set X-Frame-Options.
2  
3 package Plack::Middleware::XFrameOptions::All;
4 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $Plack::Middleware::XFrameOptions::All::VERSION = '0.2';
6 }
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Plack::Middleware::XFrameOptions::All - Plack middleware to set X-Frame-Options.
14  
15 =head1 VERSION
16  
17 version 0.2
18  
19 =head1 DESCRIPTION
20  
21 This module will setup X-Frame-Options header to protect clickjacking issue.
22 This header has been supported by IE8+, Fx 3.6.9+, Google Chrome.
23  
24 =head1 SYNOPSIS
25  
26 use Plack::Builder;
27 builder {
28 enable 'XFrameOptions::All', policy => 'sameorigin'; // or 'deny'
29 }
30  
31 =cut
32  
33 1 ▶use parent 'Plack::Middleware';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use Plack::Util::Accessor qw/policy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 0 ▶sub call {
Subroutine call: not called CC=1 SCAR=6.9
Pod documented
39 0 my ($self, $env) = @_;
40  
41 0 my $res = $self->app->($env);
42 0 ▶ Plack::Util::response_cb($res, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
43 0 my $res = shift;
44  
45 0 my $h = Plack::Util::headers($res->[1]);
46  
47 # Only process text/html.
48 0 ▶ my $ct = $h->get('Content-Type') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ct = $h->get("Content-Type") or return 0 0 0
49 0 ▶ return unless $ct =~ qr{text/html};
Branch: 1 branch
BranchTrueFalseTotal
unless $ct =~ qr"text/html" 0 0 0
50  
51 0 $h->set('X-Frame-Options', $self->policy);
52 0 });
53 }
54  
55 0 ▶sub prepare_app {
Subroutine prepare_app: not called CC=2 SCAR=17.9
Pod documented
56 0 my $self = shift;
57 0 ▶ $self->policy('sameorigin') unless defined $self->policy;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->policy 0 0 0
58 }
59  
60 =head1 AUTHOR
61  
62 Gea-Suan Lin, C<< <gslin at gslin.org> >>
63  
64 =head1 LICENSE AND COPYRIGHT
65  
66 Copyright 2011 Gea-Suan Lin.
67  
68 This software is released under 3-clause BSD license. See
69 L<http://www.opensource.org/licenses/bsd-license.php> for more
70 information.
71  
72 =cut
73  
74 1 1;
↑ Summary