blib/lib/CatalystX/AppBuilder.pm

filter: Statementstmt 18.6% 16 / 86 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 20.0% 2 / 10 Podpod 66.6% 2 / 3 totaltotal 14.2% 20 / 140 CC 23 SCAR 41.1
CC
23
Cov
13%
bootstrap
110.0
inherited_path_to
72.0
BUILD
42.0
CRAP 60.9
↑ Summary
1 package CatalystX::AppBuilder;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use namespace::clean -except => qw(meta);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '0.00011';
6  
7 1 has appname => (
8 is => 'ro',
9 isa => 'Str',
10 required => 1,
11 );
12  
13 1 has appmeta => (
14 init_arg => undef,
15 is => 'ro',
16 isa => 'Moose::Meta::Class',
17 lazy_build => 1
18 );
19  
20 1 has debug => (
21 is => 'ro',
22 isa => 'Bool',
23 default => 0,
24 );
25  
26 1 has version => (
27 is => 'ro',
28 isa => 'Str',
29 required => 1,
30 lazy_build => 1,
31 );
32  
33 1 has superclasses => (
34 is => 'ro',
35 isa => 'Maybe[ArrayRef]',
36 required => 1,
37 lazy_build => 1,
38 );
39  
40 1 has config => (
41 is => 'ro',
42 isa => 'HashRef',
43 lazy_build => 1,
44 );
45  
46 1 has plugins => (
47 is => 'ro',
48 isa => 'ArrayRef',
49 lazy_build => 1,
50 );
51  
52 0 ▶sub _build_version { '0.00001' }
Subroutine _build_version: not called CC=1 SCAR=6.9
53 0 ▶sub _build_superclasses { [ 'Catalyst' ] }
Subroutine _build_superclasses: not called CC=1 SCAR=6.9
54 0 ▶sub _build_config {
Subroutine _build_config: not called CC=1 SCAR=6.9
55 0 my $self = shift;
56 0 my %config = (
57 name => $self->appname,
58 );
59 0 return \%config;
60 }
61  
62 0 ▶sub _build_plugins {
Subroutine _build_plugins: not called CC=2 SCAR=17.9
63 0 my $self = shift;
64 0 my @plugins = qw(ConfigLoader);
65 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
66 0 unshift @plugins, '-Debug';
67 }
68 0 return \@plugins;
69 }
70  
71 0 ▶sub BUILD {
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod undocumented
72 0 my $self = shift;
73  
74 0 my $appname = $self->appname;
75 0 my $meta = Moose::Util::find_meta( $appname );
76 0 ▶ if (! $meta || ! $appname->isa('Catalyst') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta and $appname->isa("Catalyst")) 0 0 0
Condition0%0/3
$meta and $appname->isa("Catalyst")
!ll&&!rl&&r
000
MC/DC0%0/2
$meta and $appname->isa("Catalyst")
$meta $appname->isa("Catalyst")
Truth table0%0/3
A and B
A= $metaB= $appname->isa("Catalyst")
ABresult
0X0
100
111
77 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
78 0 print STDERR "Defining $appname via " . (blessed $self) . "\n";
79 }
80 0 $meta = Moose::Meta::Class->create(
81 $appname => (
82 version => $self->version,
83 superclasses => $self->superclasses
84 )
85 );
86  
87 0 ▶ if ($appname->isa('Catalyst')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($appname->isa("Catalyst")) 0 0 0
88 # Don't let the base class fool us!
89 0 delete $appname->config->{home};
90 0 delete $appname->config->{root};
91 }
92 # Fugly, I know, but we need to load Catalyst in the app's namespace
93 # for many things to take effect.
94 0 eval <<" EOCODE";
95 package $appname;
96 use Catalyst;
97 EOCODE
98 0 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
99 }
100 0 return $meta;
101 }
102  
103 0 ▶sub bootstrap {
Subroutine bootstrap: not called CC=10 SCAR=47.0
104 0 my $self = shift;
105 0 my $runsetup = shift;
106 0 my $appclass = $self->appname;
107  
108 0 ▶ if (! $runsetup) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($runsetup) 0 0 0
109 # newer catalyst now uses Catalyst::ScriptRunner.
110 # run setup if we were explicitly asked for, or we were called from
111 # within Catalyst::ScriptRunner
112 0 my $i = 1;
113 0 $runsetup = 1;
114 0 ▶ while (my @caller = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = caller $i++) 0 0 0
115 0 my $package = $caller[0];
116 0 my $sub = $caller[3];
117  
118 # DO NOT run setup if we're being recursively called from
119 # an inherited AppBuilder
120 0 ▶ if ($package->isa('Class::MOP::Class')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($package->isa('Class::MOP::Class')) { } 0 0 0
elsif ($package->isa('Catalyst::ScriptRunner')) { } 0 0 0
elsif ($package->isa('Catalyst::Restarter')) { } 0 0 0
121 0 ▶ if ($sub =~ /superclasses$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub =~ /superclasses$/) 0 0 0
122 0 $runsetup = 0;
123 0 last;
124 }
125 } elsif ($package->isa('Catalyst::ScriptRunner')) {
126 0 last;
127 } elsif ($package->isa('Catalyst::Restarter')) {
128 0 last;
129 }
130 }
131 }
132  
133 0 ▶ if ($runsetup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runsetup) 0 0 0
134 0 my @plugins;
135 my %plugins;
136 0 foreach my $plugin (@{ $self->plugins }) {
137 0 ▶ if ($plugins{$plugin}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugins{$plugin}++) { } 0 0 0
138 0 warn "$plugin appears multiple times in the plugin list! Ignoring...";
139 } else {
140 0 push @plugins, $plugin;
141 }
142 }
143  
144 0 $appclass->config( $self->config );
145 0 $appclass->setup( @plugins );
146 }
147 }
148  
149 0 ▶sub inherited_path_to {
Subroutine inherited_path_to: not called CC=8 SCAR=42.8
Pod documented
150 0 my $self = shift;
151  
152 # XXX You have to have built the class
153 0 my $meta = Moose::Util::find_meta($self->appname);
154  
155 0 my @inheritance;
156 0 foreach my $class ($meta->linearized_isa) {
157 0 ▶ next if ! $class->isa( 'Catalyst' );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa("Catalyst") 0 0 0
158 0 ▶ next if $class eq 'Catalyst';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "Catalyst" 0 0 0
159  
160 0 push @inheritance, $class;
161 }
162  
163 0 my @paths = @_;
164 return map {
165 0 my $m = $_;
166 0 $m =~ s/::/\//g;
167 0 $m .= '.pm';
168 0 my $f = Path::Class::File->new($INC{$m})->parent;
169 0 ▶ DESCENT: while ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
170 0 for my $stopper (qw(Makefile.PL Build.PL dist.ini minil.toml)) {
171 0 ▶ if (-f $f->file($stopper)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $f->file($stopper)) 0 0 0
172 0 $f = $f->subdir(@paths)->stringify;
173 0 last DESCENT;
174 }
175 }
176 0 ▶ last if $f->stringify eq $f->parent->stringify;
Branch: 1 branch
BranchTrueFalseTotal
if $f->stringify eq $f->parent->stringify 0 0 0
177 0 $f = $f->parent;
178 }
179 0 $f;
180 } @inheritance;
181 }
182  
183 0 ▶sub app_path_to {
Subroutine app_path_to: not called CC=1 SCAR=6.9
Pod documented
184 0 my $self = shift;
185  
186 0 return $self->appname->path_to(@_)->stringify;
187 }
188
189  
190 1 __PACKAGE__->meta->make_immutable();
191  
192 1 1;
193  
194  
195 __END__
↑ Summary