| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | if ( $self->can($field) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->disable_if_debug and $c->debug
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->_cache(''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $self->compress(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | ▶ | if ( $self->_cache | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%2/6
$self->_cache and $c->can("cache") and $data = $c->cache->get($self->_cache)
$self->_cache and $c->can("cache")
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | $data = $c->stash->{ $self->key }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | unless ($cached) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | ▶ | $data = minify($data) if ( $self->compress ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | $data = "/* " . $self->copyright . " */\n" . $data | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->_cache and $c->can("cache")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | if ( $self->_cache && $c->can('cache') ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||