blib/lib/Catalyst/View/JavaScript.pm

filter: Statementstmt 86.5% 45 / 52 Branchbran 70.0% 14 / 20 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 69.7% 76 / 109 CC 17 SCAR 26.7
CC
17
Cov
74%
process
25.0
new
4.1
cache
2.0
CRAP 14.4
↑ Summary
1 package Catalyst::View::JavaScript;
2 1 our $VERSION = '0.995';
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use JavaScript::Minifier::XS qw(minify);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base qw|Catalyst::View|;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 __PACKAGE__->mk_accessors(
11 qw(compress disable_if_debug stash key output _cache copyright));
12  
13 1 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
14 1 my $self = shift->next::method(@_);
15 1 my ( $c, $arguments ) = @_;
16 1 my %config = (
17 compress => 1,
18 stash => 1,
19 key => "js",
20 disable_if_debug => 1,
21 %$arguments
22 );
23 1 for my $field ( keys %config ) {
24 5 ▶ next if $field =~ /^catalyst/;
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /^catalyst/ 1 4 5
25 4 ▶ if ( $self->can($field) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($field)) { } 4 0 4
26 4 $self->$field( $config{$field} );
27 }
28 else {
29 0 $c->log->warn("Unknown config parameter '$field'");
30 }
31 }
32 1 return $self;
33 }
34  
35 0 ▶sub cache {
Subroutine cache: not called CC=1 SCAR=6.9
Pod documented
36 0 my $self = shift;
37 0 $self->_cache(@_);
38 0 return $self;
39 }
40  
41 5 ▶sub process {
Subroutine process: called CC=14 SCAR=32.2
Pod documented
42 5 my ( $self, $c ) = @_;
43 5 my $data = '';
44 5 my $cached = 0;
45 5 ▶ if ( $self->disable_if_debug && $c->debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->disable_if_debug and $c->debug) 0 5 5
Condition33%1/3
$self->disable_if_debug and $c->debug
!ll&&!rl&&r
050
MC/DC0%0/2
$self->disable_if_debug and $c->debug
$self->disable_if_debug $c->debug
Truth table33%1/3
A and B
A= $self->disable_if_debugB= $c->debug
ABresult
0X0
100
111
46 0 $self->_cache('');
47 0 $self->compress(0);
48 }
49 5 ▶ if ( $self->_cache
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_cache and $c->can('cache') and $data = $c->cache->get($self->_cache)) { } 0 5 5
elsif ($self->output) { } 1 4 5
elsif ($self->stash and $self->key) { } 4 0 4
Condition33%2/6
$self->_cache and $c->can("cache") and $data = $c->cache->get($self->_cache)
!ll&&!rl&&r
500
$self->_cache and $c->can("cache")
!ll&&!rl&&r
500
MC/DC0%0/3
$self->_cache and $c->can("cache") and $data = $c->cache->get($self->_cache)
$self->_cache $c->can("cache") $data = $c->cache->get($self->_cache)
Truth table25%1/4
A and B and C
A= $self->_cacheB= $c->can("cache")C= $data = $c->cache->get($self->_cache)
ABCresult
0XX0
10X0
1100
1111
50 && $c->can('cache')
51 && ( $data = $c->cache->get( $self->_cache ) ) )
52 {
53 0 $cached = 1;
54 }
55 elsif ( $self->output ) {
56 1 $data = $c->res->output;
57 }
58 ▶ elsif ( $self->stash && $self->key ) {
Condition33%1/3
$self->stash and $self->key
!ll&&!rl&&r
004
MC/DC0%0/2
$self->stash and $self->key
$self->stash $self->key
Truth table33%1/3
A and B
A= $self->stashB= $self->key
ABresult
0X0
100
111
59 4 $data = $c->stash->{ $self->key };
60 }
61 5 ▶ unless ($cached) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cached) 5 0 5
62 5 ▶ $data = minify($data) if ( $self->compress );
Branch: 1 branch
BranchTrueFalseTotal
if $self->compress 4 1 5
63 5 ▶ $data = "/* " . $self->copyright . " */\n" . $data
Branch: 1 branch
BranchTrueFalseTotal
if $self->copyright 1 4 5
64 if ( $self->copyright );
65 }
66  
67 5 $c->res->content_type("text/javascript");
68 5 $c->res->output($data);
69 5 ▶ $c->cache->set( $self->_cache, $data )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_cache and $c->can("cache") 0 5 5
Condition33%1/3
$self->_cache and $c->can("cache")
!ll&&!rl&&r
500
MC/DC0%0/2
$self->_cache and $c->can("cache")
$self->_cache $c->can("cache")
Truth table33%1/3
A and B
A= $self->_cacheB= $c->can("cache")
ABresult
0X0
100
111
70 if ( $self->_cache && $c->can('cache') );
71 }
72  
73 1 1;
74  
75 __END__
↑ Summary