blib/lib/Catalyst/Plugin/Static/Simple/ByClass.pm

filter: Statementstmt 94.8% 37 / 39 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 83.3% 50 / 60 CC 7 SCAR 15.3
CC
7
Cov
86%
__ANON__
8.2
BEGIN
1.0
BEGIN
1.0
CRAP 4.6
↑ Summary
1 package Catalyst::Plugin::Static::Simple::ByClass;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Class::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 with 'Catalyst::Plugin::Static::Simple';
11  
12 3 our $VERSION = '0.005';
13  
14 =head1 NAME
15  
16 Catalyst::Plugin::Static::Simple::ByClass - locate static content in @INC
17  
18 =head1 SYNOPSIS
19  
20 use Catalyst qw(
21 Static::Simple::ByClass
22 );
23
24 __PACKAGE__->config(
25 'Plugin::Static::Simple::ByClass' => {
26 classes => [ qw( MyClass::Foo ) ]
27 }
28 );
29  
30 =head1 DESCRIPTION
31  
32 Catalyst::Plugin::Static::Simple::ByClass is a subclass of
33 Catalyst::Plugin::Static::Simple. It extends the base class to alter
34 the include_path config to include @INC paths for classes. The idea
35 is that you can distribute static files (.js and .css for example)
36 with applications, and those files can be served during development
37 directly from the installed @INC location.
38
39 =head1 METHODS
40  
41 Only new or overridden method are documented here.
42  
43 =head2 setup
44  
45 Calls next::method and then checks the B<classes> config option
46 for a list of class names to require and add to the include_path.
47  
48 =cut
49  
50 1 ▶before setup_finalize => sub {
Subroutine __ANON__: called CC=7 SCAR=21.1
51 1 my $c = shift;
52  
53 $c->log->warn(
54 "Deprecated 'static' config key used, please use the key 'Plugin::Static::Simple::ByClass' instead"
55 1 ▶ ) if exists $c->config->{static};
Branch: 1 branch
BranchTrueFalseTotal
if exists $c->config->{"static"} 0 1 1
56  
57 my $config = $c->config->{'Plugin::Static::Simple::ByClass'}
58 = Catalyst::Utils::merge_hashes(
59 $c->config->{'Plugin::Static::Simple::ByClass'} || {},
60 1 ▶ $c->config->{static} || {} );
Condition50%2/4
$c->config->{'Plugin::Static::Simple::ByClass'} || {}
l!l
10
$c->config->{'static'} || {}
l!l
01
MC/DC0%0/1
$c->config->{'Plugin::Static::Simple::ByClass'} || {}
$c->config->{'Plugin::Static::Simple::ByClass'}
MC/DC0%0/1
$c->config->{'static'} || {}
$c->config->{'static'}
Truth table50%1/2
A
A= $c->config->{'Plugin::Static::Simple::ByClass'}
Aresult
11
00
Truth table50%1/2
A
A= $c->config->{'static'}
Aresult
11
00
61  
62 1 ▶ for my $class ( @{ $config->{classes} || [] } ) {
Condition50%1/2
$config->{'classes'} || []
l!l
10
MC/DC0%0/1
$config->{'classes'} || []
$config->{'classes'}
Truth table50%1/2
A
A= $config->{'classes'}
Aresult
11
00
63  
64 1 eval "require $class";
65 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
66 0 $c->error( __PACKAGE__ . " : Failed to load $class" );
67 0 return;
68 }
69 1 my $base = Class::Inspector->loaded_filename($class);
70 1 $base =~ s/\.pm$//;
71 1 push( @{ $c->config->{'Plugin::Static::Simple'}->{include_path} }, Path::Class::dir($base) );
72  
73 }
74 1 return $c;
75 3 };
76  
77 3 1;
78  
79 __END__
↑ Summary