File Coverage

blib/lib/Mite/Compiled.pm.mite.pm
Criterion Covered Total %
statement 90 165 54.5
branch 22 102 21.5
condition 7 69 10.1
subroutine 19 33 57.5
pod 0 7 0.0
total 138 376 36.7


line stmt bran cond sub pod time code
1             {
2              
3             use strict;
4 106     106   804 use warnings;
  106         312  
  106         3158  
5 106     106   495 no warnings qw( once void );
  106         688  
  106         3420  
6 106     106   528  
  106         202  
  106         11561  
7             our $USES_MITE = "Mite::Class";
8             our $MITE_SHIM = "Mite::Shim";
9             our $MITE_VERSION = "0.010007";
10              
11             # Mite keywords
12             BEGIN {
13             my ( $SHIM, $CALLER ) = ( "Mite::Shim", "Mite::Compiled" );
14 106     106   561 (
15             *after, *around, *before, *extends, *field,
16             *has, *param, *signature_for, *with
17             )
18             = do {
19 106         274  
20             no warnings 'redefine';
21             (
22 106     106   695 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
  106         277  
  106         22125  
23             sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
24 0     0   0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
25 0     0   0 sub { },
26 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
27       0     sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
28 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
29 212     212   2980 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
30 0     0   0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
31 106     106   1058 );
32 0     0   0 }
33 106         16827  
34             # Mite imports
35             BEGIN {
36             require Scalar::Util;
37             *STRICT = \&Mite::Shim::STRICT;
38             *bare = \&Mite::Shim::bare;
39 106     106   723 *blessed = \&Scalar::Util::blessed;
40 106         343 *carp = \&Mite::Shim::carp;
41 106         229 *confess = \&Mite::Shim::confess;
42 106         249 *croak = \&Mite::Shim::croak;
43 106         220 *false = \&Mite::Shim::false;
44 106         12299 *guard = \&Mite::Shim::guard;
45 106         248 *lazy = \&Mite::Shim::lazy;
46 106         355 *ro = \&Mite::Shim::ro;
47 106         359 *rw = \&Mite::Shim::rw;
48 106         12584 *rwp = \&Mite::Shim::rwp;
49 106         224 *true = \&Mite::Shim::true;
50 106         268 }
51 106         306  
52 106         3614 # Gather metadata for constructor and destructor
53             no strict 'refs';
54             my $class = shift;
55             $class = ref($class) || $class;
56             my $linear_isa = mro::get_linear_isa($class);
57 106     106   667 return {
  106         256  
  106         29887  
58 82     82   220 BUILD => [
59 82   33     525 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
60 82         521 map { "$_\::BUILD" } reverse @$linear_isa
61             ],
62             DEMOLISH => [
63 82 50       189 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  82         851  
  0         0  
64 82         430 map { "$_\::DEMOLISH" } @$linear_isa
65             ],
66             HAS_BUILDARGS => $class->can('BUILDARGS'),
67 82 50       214 HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
  82         1835  
  0         0  
68 82         360 };
  82         330  
69             }
70              
71             # Standard Moose/Moo-style constructor
72             my $class = ref( $_[0] ) ? ref(shift) : shift;
73             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
74             my $self = bless {}, $class;
75             my $args =
76             $meta->{HAS_BUILDARGS}
77 99 50   99 0 394 ? $class->BUILDARGS(@_)
78 99   66     814 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
79 99         369 my $no_build = delete $args->{__no_BUILD__};
80              
81             # Attribute file (type: Path)
82             # has declaration, file lib/Mite/Compiled.pm, line 23
83 99 50       723 if ( exists $args->{"file"} ) {
  0 50       0  
84 99         263 do {
85             my $coerced_value = do {
86             my $to_coerce = $args->{"file"};
87             (
88 99 50       435 (
89 0         0 do {
90 0         0 use Scalar::Util ();
91 0         0 Scalar::Util::blessed($to_coerce)
92             and $to_coerce->isa(q[Path::Tiny]);
93             }
94             )
95 106     106   819 ) ? $to_coerce : (
  106         12526  
  106         64304  
96 0 0       0 do {
97              
98             defined($to_coerce) and do {
99             ref( \$to_coerce ) eq 'SCALAR'
100             or ref( \( my $val = $to_coerce ) ) eq
101             'SCALAR';
102             }
103             )
104 0 0       0 ? scalar(
105 0 0       0 do { local $_ = $to_coerce; Path::Tiny::path($_) }
106             )
107             : (
108             do {
109              
110             defined($to_coerce) && !ref($to_coerce)
111             or Scalar::Util::blessed($to_coerce) && (
112 0         0 sub {
  0         0  
113             require overload;
114             overload::Overloaded( ref $_[0] or $_[0] )
115             and
116             overload::Method( ( ref $_[0] or $_[0] ),
117             $_[1] );
118             }
119             )->( $to_coerce, q[""] );
120             )
121 0     0   0 ? scalar(
122 0 0 0     0 do { local $_ = $to_coerce; Path::Tiny::path($_) }
      0        
123             )
124             : ( ( ref($to_coerce) eq 'ARRAY' ) ) ? scalar(
125             do { local $_ = $to_coerce; Path::Tiny::path(@$_) }
126             )
127 0 0 0     0 : $to_coerce;
      0        
128             };
129             blessed($coerced_value) && $coerced_value->isa("Path::Tiny")
130             or croak "Type check failed in constructor: %s should be %s",
131 0         0 "file", "Path";
  0         0  
132             $self->{"file"} = $coerced_value;
133             };
134 0 0       0 }
  0 0       0  
  0 0       0  
    0          
135              
136             # Attribute source (type: Mite::Source)
137             # has declaration, file lib/Mite/Compiled.pm, line 25
138 0 0 0     0 croak "Missing key in constructor: source"
139             unless exists $args->{"source"};
140             blessed( $args->{"source"} ) && $args->{"source"}->isa("Mite::Source")
141 0         0 or croak "Type check failed in constructor: %s should be %s",
142             "source", "Mite::Source";
143             $self->{"source"} = $args->{"source"};
144             require Scalar::Util && Scalar::Util::weaken( $self->{"source"} )
145             if ref $self->{"source"};
146              
147             # Call BUILD methods
148 99 50       351 $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
149 99 50 33     1312  
150             # Unrecognized parameters
151             my @unknown = grep not(/\A(?:file|source)\z/), keys %{$args};
152 99         612 @unknown
153             and croak(
154 99 50 33     1478 "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
155              
156             return $self;
157 99 50 33     494 }
  99 50       683  
158              
159             # Used by constructor to call BUILD methods
160 99         247 my $class = ref( $_[0] );
  99         991  
161             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
162 99 50       421 $_->(@_) for @{ $meta->{BUILD} || [] };
163             }
164              
165 99         459 # Destructor should call DEMOLISH methods
166             my $self = shift;
167             my $class = ref($self) || $self;
168             my $meta = ( $Mite::META{$class} ||= $class->__META__ );
169             my $in_global_destruction =
170 0     0 0 0 defined ${^GLOBAL_PHASE}
171 0   0     0 ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
172 0 0       0 : Devel::GlobalDestruction::in_global_destruction();
  0         0  
173             for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
174             my $e = do {
175             local ( $?, $@ );
176             eval { $demolisher->( $self, $in_global_destruction ) };
177 0     0   0 $@;
178 0   0     0 };
179 0   0     0 no warnings 'misc'; # avoid (in cleanup) warnings
180 0 0       0 die $e if $e; # rethrow
181             }
182             return;
183             }
184 0 0       0  
  0         0  
185 0         0 my $__XS = !$ENV{PERL_ONLY}
186 0         0 && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
187 0         0  
  0         0  
188 0         0 # Accessors for file
189             # has declaration, file lib/Mite/Compiled.pm, line 23
190 106     106   856 @_ > 1
  106         254  
  106         12655  
191 0 0       0 ? do {
192             my $value = do {
193 0         0 my $to_coerce = $_[1];
194             (
195             (
196             do {
197             use Scalar::Util ();
198             Scalar::Util::blessed($to_coerce)
199             and $to_coerce->isa(q[Path::Tiny]);
200             }
201             )
202             ) ? $to_coerce : (
203             do {
204 0         0  
205 0         0 defined($to_coerce) and do {
206             ref( \$to_coerce ) eq 'SCALAR'
207             or ref( \( my $val = $to_coerce ) ) eq 'SCALAR';
208             }
209 106     106   834 )
  106         259  
  106         31945  
210 0 0       0 ? scalar(
211             do { local $_ = $to_coerce; Path::Tiny::path($_) }
212             )
213             : (
214             do {
215              
216             defined($to_coerce) && !ref($to_coerce)
217             or Scalar::Util::blessed($to_coerce) && (
218 0 0       0 sub {
219 0 0       0 require overload;
220             overload::Overloaded( ref $_[0] or $_[0] )
221             and overload::Method( ( ref $_[0] or $_[0] ),
222             $_[1] );
223             }
224             )->( $to_coerce, q[""] );
225 0         0 )
  0         0  
226             ? scalar(
227             do { local $_ = $to_coerce; Path::Tiny::path($_) }
228             )
229             : ( ( ref($to_coerce) eq 'ARRAY' ) ) ? scalar(
230             do { local $_ = $to_coerce; Path::Tiny::path(@$_) }
231             )
232             : $to_coerce;
233             };
234 0     0   0 blessed($value) && $value->isa("Path::Tiny")
235 0 0 0     0 or croak( "Type check failed in %s: value should be %s",
      0        
236             "accessor", "Path" );
237             $_[0]{"file"} = $value;
238             $_[0];
239 0 0 0     0 }
      0        
240             : do {
241             (
242             exists( $_[0]{"file"} ) ? $_[0]{"file"} : (
243 0         0 $_[0]{"file"} = do {
  0         0  
244             my $default_value = do {
245             my $to_coerce =
246 0 0       0 $Mite::Compiled::__file_DEFAULT__->(
  0 0       0  
  0 0       0  
    0          
247             $_[0] );
248             (
249             (
250 0 0 0     0 do {
251             use Scalar::Util ();
252             Scalar::Util::blessed($to_coerce)
253 0         0 and $to_coerce->isa(q[Path::Tiny]);
254 0         0 }
255             )
256 100 50   100 0 1810 ) ? $to_coerce : (
257             do {
258              
259 100 100       337 defined($to_coerce) and do {
260 97         177 ref( \$to_coerce ) eq 'SCALAR'
261 97         438 or ref( \( my $val = $to_coerce ) )
262             eq 'SCALAR';
263             }
264             )
265             ? scalar(
266             do {
267 106     106   748 local $_ = $to_coerce;
  106         301  
  106         66303  
268 97 50       651 Path::Tiny::path($_);
269             }
270             )
271             : (
272             do {
273              
274             defined($to_coerce) && !ref($to_coerce)
275             or Scalar::Util::blessed($to_coerce) && (
276 97 50       695 sub {
277 97 50       811 require overload;
278             overload::Overloaded(
279             ref $_[0]
280             or $_[0]
281             )
282             and overload::Method(
283             ( ref $_[0] or $_[0] ), $_[1] );
284             }
285 97         272 )->( $to_coerce, q[""] );
286 97         355 )
287             ? scalar(
288             do {
289             local $_ = $to_coerce;
290             Path::Tiny::path($_);
291             }
292             )
293             : ( ( ref($to_coerce) eq 'ARRAY' ) ) ? scalar(
294             do {
295             local $_ = $to_coerce;
296 0     0   0 Path::Tiny::path(@$_);
297 0 0 0     0 }
      0        
298             )
299             : $to_coerce;
300             };
301             blessed($default_value)
302             && $default_value->isa("Path::Tiny")
303             or croak(
304 0 0 0     0 "Type check failed in default: %s should be %s",
      0        
305             "file", "Path" );
306             $default_value;
307             }
308             )
309 0         0 )
310 0         0 }
311             }
312              
313             # Accessors for source
314 97 0       753 # has declaration, file lib/Mite/Compiled.pm, line 25
    0          
    50          
    50          
315 0         0 if ($__XS) {
316 0         0 Class::XSAccessor->import(
317             chained => 1,
318             "getters" => { "source" => "source" },
319             );
320             }
321 97 50 33     3685 else {
322             *source = sub {
323             @_ == 1 or croak('Reader "source" usage: $self->source()');
324             $_[0]{"source"};
325             };
326 97         1346 }
327              
328             my $object = do { $_[0]{"source"} };
329             blessed($object) or croak("source is not a blessed object");
330             $object;
331             }
332              
333             # Delegated methods for source
334             # has declaration, file lib/Mite/Compiled.pm, line 25
335              
336             # See UNIVERSAL
337             my ( $self, $role ) = @_;
338             our %DOES;
339             return $DOES{$role} if exists $DOES{$role};
340             return 1 if $role eq __PACKAGE__;
341             return $self->SUPER::DOES($role);
342             }
343              
344             # Alias for Moose/Moo-compatibility
345             shift->DOES(@_);
346             }
347              
348             # Method signatures
349 227     227   373 our %SIGNATURE_FOR;
  227         496  
350 227 50       906  
351 227         1351 $SIGNATURE_FOR{"_source_file2compiled_file"} = sub {
352             my $__NEXT__ = shift;
353              
354             my ( %tmp, $tmp, @head );
355              
356 96     96 0 430 @_ == 2
357 131     131 0 449 or croak(
358             "Wrong number of parameters in signature for %s: got %d, %s",
359             "_source_file2compiled_file",
360             scalar(@_),
361 0     0 0   "expected exactly 2 parameters"
362 0           );
363 0 0          
364 0 0         @head = splice( @_, 0, 1 );
365 0            
366             # Parameter invocant (type: Defined)
367             ( defined( $head[0] ) )
368             or croak(
369             "Type check failed in signature for _source_file2compiled_file: %s should be %s",
370 0     0 0   "\$_[0]", "Defined"
371             );
372              
373             # Parameter $_[0] (type: Defined)
374             ( defined( $_[0] ) )
375             or croak(
376             "Type check failed in signature for _source_file2compiled_file: %s should be %s",
377             "\$_[1]", "Defined"
378             );
379              
380             do { @_ = ( @head, @_ ); goto $__NEXT__ };
381             };
382              
383             1;
384