Controller/AutoAssets.pm

filter: Statementstmt 93.3% 56 / 60 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 3 totaltotal 78.9% 75 / 95 CC 7 SCAR 6.7
CC
7
Cov
84%
index
3.6
_resolve_handler_class
3.1
unknown_asset
2.0
CRAP 1.9
« Controller/AutoAssets/Handler/JS.pm ↑ Summary
1 package Catalyst::Controller::AutoAssets;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 our $VERSION = '0.40';
6  
7 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 require Module::Runtime;
10  
11 4 ▶BEGIN { extends 'Catalyst::Controller' }
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 has 'type', is => 'ro', isa => 'Str', required => 1;
14 4 ▶has 'no_logs', is => 'rw', isa => 'Bool', default => sub {1};
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 4 has '_module_version', is => 'ro', isa => 'Str', default => $VERSION;
17  
18 # Save the build params (passed to constructor)
19 4 has '_build_params', is => 'ro', isa => 'HashRef', required => 1;
20 4 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
21 4 my ($orig, $class, $c, @args) = @_;
22 4 ▶ my %params = (ref($args[0]) eq 'HASH') ? %{ $args[0] } : @args; # <-- arg as hash or hashref
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 4 0 4
23 4 $params{_build_params} = {%params};
24 4 return $class->$orig($c,\%params);
25 4 };
26  
27 # The Handler (which is determined by the asset type) is
28 # where most of the actual work gets done:
29 has '_Handler' => (
30 is => 'ro', init_arg => undef, lazy => 1,
31 does => 'Catalyst::Controller::AutoAssets::Handler',
32 handles => [qw(request asset_path html_head_tags)],
33 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 4 my $self = shift;
35 4 my $class = $self->_resolve_handler_class($self->type);
36 return $class->new({
37 4 %{$self->_build_params},
38 Controller => $self
39 });
40 }
41 4 );
42  
43 # Delegate all other function calls to the Handler to support future
44 # Handler classes and new methods
45 4 our $AUTOLOAD;
46 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
47 0 $AUTOLOAD =~ /([^:]+)$/;
48 0 eval "sub $1 { (shift)->_Handler->$1(\@_); }";
49 0 goto $_[0]->can($1);
50 }
51  
52 4 ▶sub _resolve_handler_class {
Subroutine _resolve_handler_class: called CC=3 SCAR=11.2
53 4 my $self = shift;
54 4 my $class = shift;
55
56 # legacy, original, lower-case, built-in type names:
57 4 my %type_aliases = ( css => 'CSS', js => 'JS', directory => 'Directory' );
58 4 ▶ $class = $type_aliases{$class} if (exists $type_aliases{$class});
Branch: 1 branch
BranchTrueFalseTotal
if exists $type_aliases{$class} 4 0 4
59
60 # Allow absolute class names using '+' prefix:
61 4 ▶ $class = $class =~ /^\+(.*)$/ ? $1
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^\+(.*)$/ ? : 0 4 4
62 : "Catalyst::Controller::AutoAssets::Handler::$class";
63 4 Module::Runtime::require_module($class);
64 4 return $class;
65 }
66  
67 4 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
68 4 my $self = shift;
69
70 # init type handler:
71 4 $self->_Handler;
72 }
73  
74 18 ▶sub index :Chained :PathPrefix {
Subroutine index: called CC=3 SCAR=12.7
Pod undocumented
75 18 my ($self, $c, @args) = @_;
76
77 # New: set 'abort' just like Static::Simple to suppress log messages:
78 18 ▶ if ( $self->no_logs && $c->log->can('abort') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->no_logs and $c->log->can("abort")) 18 0 18
Condition33%1/3
$self->no_logs and $c->log->can("abort")
!ll&&!rl&&r
0018
MC/DC0%0/2
$self->no_logs and $c->log->can("abort")
$self->no_logs $c->log->can("abort")
Truth table33%1/3
A and B
A= $self->no_logsB= $c->log->can("abort")
ABresult
0X0
100
111
79 18 $c->log->abort( 1 );
80 }
81
82 18 $self->request($c,@args);
83 0 $c->detach;
84 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 2 ▶sub unknown_asset {
Subroutine unknown_asset: called CC=2 SCAR=7.1
Pod undocumented
87 2 my ($self,$c,$asset) = @_;
88 2 ▶ $asset ||= $c->req->path;
Condition33%1/3
$asset ||= $c->req->path
l!l&&r!l&&!r
200
MC/DC0%0/2
$asset ||= $c->req->path
$asset $c->req->path
Truth table33%1/3
A ||= B
A= $assetB= $c->req->path
ABresult
1X1
011
000
89 2 $c->res->status(404);
90 # Clear any other headers that might have been set, like Etag. We don't
91 # want to allow negative caching
92 2 $c->res->headers->clear;
93 2 $c->res->header( 'Content-Type' => 'text/plain' );
94 2 $c->res->body( "No such asset '$asset'" );
95 2 return $c->detach;
96 }
97  
98 4 1;
99  
100 __END__
« Controller/AutoAssets/Handler/JS.pm ↑ Summary