blib/lib/Poet/Environment.pm

filter: Statementstmt 97.9% 97 / 99 Branchbran 72.7% 16 / 22 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 20 / 20 Podpod n/a totaltotal 90.7% 137 / 151 CC 27 SCAR 8.7
CC
27
Cov
92%
__ANON__
4.0
generate_subdir_methods
4.0
__ANON__
3.1
CRAP 2.4
« blib/lib/Poet/Test/Class.pm ↑ Summary blib/lib/Poet/App.pm »
1 package Poet::Environment;
2 12 $Poet::Environment::VERSION = '0.16';
3 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Poet::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Poet::Tools qw(can_load catdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 has 'app_name' => ( required => 1 );
9 12 has 'conf' => ();
10 12 has 'importer' => ();
11 12 has 'log_manager' => ();
12 12 has 'root_dir' => ( required => 1 );
13  
14 12 my ($current_env);
15  
16 12 ▶method subdirs () { [qw(bin comps conf data db lib logs static t)] }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine subdirs: called CC=1 SCAR=0.0
17  
18 12 ▶method app_class ($class_name) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine app_class: called CC=3 SCAR=11.0
Subroutine __ANON__: called CC=3 SCAR=11.0
19 63 my $app_class_name = join( "::", $self->app_name, $class_name );
20 63 my $env_class_name = join( "::", "Poet", $class_name );
21 return
22 63 ▶ can_load($app_class_name) ? $app_class_name
Branch: 4 branches
BranchTrueFalseTotal
can_load($app_class_name) ? : 20 43 63
can_load($env_class_name) ? : 43 0 43
can_load($app_class_name) ? : 85 212 297
can_load($env_class_name) ? : 131 45 176
23 : can_load($env_class_name) ? $env_class_name
24 : die "cannot load $app_class_name or $class_name";
25 12 }
26  
27 12 ▶method generate_subdir_methods ($class:) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine generate_subdir_methods: called CC=4 SCAR=13.9
28 7 foreach my $subdir ( 'root', @{ $class->subdirs() } ) {
29 70 my $dir_method = $subdir . "_dir";
30 70 ▶ has $dir_method => () if $subdir ne 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $subdir ne "root" 63 7 70
31 70 ▶ my $path_method = $subdir eq 'root' ? "path" : $subdir . "_path";
Branch: 1 branch
BranchTrueFalseTotal
$subdir eq 'root' ? : 7 63 70
32 __PACKAGE__->meta->add_method(
33 $path_method,
34 3 ▶ sub {
Subroutine data_path: called CC=2 SCAR=7.2
Subroutine conf_path: called CC=2 SCAR=7.2
35 3 my ( $self, $relpath ) = @_;
36 3 ▶ croak "$path_method expects relative path as argument"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $relpath 0 3 3
unless defined $relpath 0 2 2
37 unless defined($relpath);
38 3 return $self->$dir_method . "/" . $relpath;
39 }
40 70 );
41 }
42 12 }
43  
44 12 ▶method initialize_current_environment ($class: %params) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine initialize_current_environment: called CC=3 SCAR=11.3
45 6 ▶ if ( defined($current_env) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_env) 0 6 6
46 0 die sprintf( "initialize_current_environment called when current_env already set (%s)",
47 $current_env->root_dir() );
48 }
49 6 ▶ $current_env = $params{env} || $class->new(%params);
Condition66%4/6
$params{'env'} || $class->new(%params)
l!l&&r!l&&!r
330
$params{'env'} || $class->new(%params)
l!l&&r!l&&!r
110
MC/DC0%0/2
$params{'env'} || $class->new(%params)
$params{'env'} $class->new(%params)
MC/DC0%0/2
$params{'env'} || $class->new(%params)
$params{'env'} $class->new(%params)
Truth table66%2/3
A || B
A= $params{'env'}B= $class->new(%params)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $params{'env'}B= $class->new(%params)
ABresult
1X1
011
000
50  
51 # Initialize logging and caching
52 #
53 6 $current_env->app_class('Log')->initialize_logging();
54 6 $current_env->app_class('Cache')->initialize_caching();
55  
56 6 return $current_env;
57 12 }
58  
59 12 ▶method current_env ($class:) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine current_env: called CC=1 SCAR=0.0
60 92 return $current_env;
61 12 }
62  
63 12 ▶method BUILD () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BUILD: called CC=3 SCAR=11.0
Subroutine __ANON__: called CC=3 SCAR=11.0
64 19 my $root_dir = $self->root_dir();
65  
66 # Unshift lib dir onto @INC
67 #
68 19 my $lib_dir = "$root_dir/lib";
69 19 ▶ unless ( $INC[0] eq $lib_dir ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($INC[0] eq $lib_dir) 19 0 19
unless ($INC[0] eq $lib_dir) 0 15 15
70 19 unshift( @INC, $lib_dir );
71 }
72  
73 # Initialize configuration
74 #
75 $self->{conf} =
76 19 $self->app_class('Conf')
77 ->new( root_dir => $root_dir, conf_dir => catdir( $root_dir, "conf" ) );
78 16 my $conf = $self->{conf};
79  
80 # Initialize importer
81 #
82 16 $self->{importer} = $self->app_class('Import')->new( env => $self );
83  
84 # Determine where our standard subdirectories (bin, comps, etc.)
85 # are. Can override in configuration with env.bin_dir, env.comps_dir,
86 # etc. Otherwise use obvious defaults.
87 #
88 0 foreach my $subdir ( @{ $self->subdirs() } ) {
89 144 my $method = $subdir . "_dir";
90 144 $self->{$method} = $conf->get( "env.$method" => "$root_dir/$subdir" );
91 }
92 12 }
93  
94 12 __PACKAGE__->generate_subdir_methods();
95 12 __PACKAGE__->meta->make_immutable();
96  
97 12 1;
98  
99 __END__
« blib/lib/Poet/Test/Class.pm ↑ Summary blib/lib/Poet/App.pm »