File Coverage

blib/lib/Plack/Middleware/UseChromeFrame.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 1 1 100.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Plack::Middleware::UseChromeFrame;
2             BEGIN {
3 2     2   48335 $Plack::Middleware::UseChromeFrame::VERSION = '1.003';
4             }
5 2     2   16 use strict;
  2         5  
  2         78  
6 2     2   6919 use parent 'Plack::Middleware';
  2         382  
  2         14  
7 2     2   23711 use Plack::Util ();
  2         5  
  2         389  
8              
9             # ABSTRACT: enable Google Chrome Frame for users who have it
10              
11             sub call {
12 2     2 1 29782 my $self = shift;
13 2         3 my ( $env ) = @_;
14 2         14 my $res = $self->app->( $env );
15              
16 2         95 my $ua = $env->{'HTTP_USER_AGENT'};
17 2 100 66     21 return $res unless defined $ua and $ua =~ /chromeframe/i;
18              
19             Plack::Util::response_cb( $res, sub {
20 1     1   28 Plack::Util::header_push( $_[0][1], 'X-UA-Compatible', 'chrome=1' );
21 1         9 return;
22 1         9 } );
23             }
24              
25             1;
26              
27              
28              
29             =pod
30              
31             =head1 NAME
32              
33             Plack::Middleware::UseChromeFrame - enable Google Chrome Frame for users who have it
34              
35             =head1 VERSION
36              
37             version 1.003
38              
39             =head1 SYNOPSIS
40              
41             # in app.psgi
42             use Plack::Builder;
43            
44             builder {
45             enable 'UseChromeFrame';
46             $app;
47             };
48              
49             =head1 DESCRIPTION
50              
51             This is a lightweight middleware that adds the C
52             header required by GoogleEChromeEFrame to take over page rendering,
53             for requests made from a browser with ChromeEFrame installed.
54              
55             =head1 SEE ALSO
56              
57             =over 4
58              
59             =item *
60              
61             GoogleEChromeEFrame L
62              
63             =item *
64              
65             L
66              
67             This is a much more aggressive middleware. Visitors running
68             InternetEExplorer without ChromeEFrame installed are prevented from
69             seeing the site at all: they only receive a page instructing them on how to
70             install ChromeEFrame.
71              
72             =back
73              
74             =head1 AUTHOR
75              
76             Aristotle Pagaltzis
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This software is copyright (c) 2011 by Aristotle Pagaltzis.
81              
82             This is free software; you can redistribute it and/or modify it under
83             the same terms as the Perl 5 programming language system itself.
84              
85             =cut
86              
87              
88             __END__