blib/lib/Plack/Middleware/DevFavicon.pm

filter: Statementstmt 54.2% 19 / 35 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 50.0% 1 / 2 totaltotal 48.1% 26 / 54 CC 5 SCAR 20.4
CC
5
Cov
44%
dev_favicon
20.0
call
6.0
__ANON__
2.0
CRAP 7.7
↑ Summary
1 package Plack::Middleware::DevFavicon;
2 1 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 our $VERSION = "0.02";
7  
8 1 ▶use parent qw(Plack::Middleware);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub call {
Subroutine call: not called CC=2 SCAR=17.9
Pod documented
14 0 my($self, $env) = @_;
15 0 my $res = $self->app->($env);
16 0 ▶ if ($env->{PATH_INFO} =~ m{ /favicon\. (?:ico|png) $}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} =~ m[ /favicon\. (?:ico|png) $]msx) 0 0 0
17 0 return $self->dev_favicon($res);
18 }
19  
20 0 return $res;
21 }
22  
23 0 ▶sub dev_favicon {
Subroutine dev_favicon: not called CC=4 SCAR=30.0
Pod undocumented
24 0 my($self, $res) = @_;
25  
26 0 my $data = '';
27 0 ▶ Plack::Util::foreach($res->[2], sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 my($buf) = @_;
29 0 $data .= $buf;
30 0 });
31  
32 0 ▶ my $type = Plack::Util::header_get($res->[1], 'content-type') =~ /png/ ? 'png' : 'ico';
Branch: 1 branch
BranchTrueFalseTotal
Plack::Util::header_get($res->[1], 'content-type') =~ /png/ ? : 0 0 0
33  
34 0 ▶ my $img = Imager->new(data => $data, type => $type) or die Imager->errstr;
Branch: 1 branch
BranchTrueFalseTotal
my $img = "Imager"->new("data", $data, "type", $type) or die "Imager"->errstr 0 0 0
35 0 ▶ $img = $img->convert(preset => 'gray') or die Imager->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$img = $img->convert("preset", "gray") or die "Imager"->errstr 0 0 0
36  
37 0 my $out;
38 0 $img->write(data => \$out, type => $type);
39  
40 0 return [$res->[0], $res->[1], [$out]];
41 }
42  
43 1 1;
44 __END__
↑ Summary