File Coverage

blib/lib/Type/Library/Compiler.pm.mite.pm
Criterion Covered Total %
statement 108 157 68.7
branch 30 92 32.6
condition 11 60 18.3
subroutine 15 26 57.6
pod 3 6 50.0
total 167 341 48.9


line stmt bran cond sub pod time code
1             {
2              
3             package Type::Library::Compiler;
4 2     2   16 use strict;
  2         5  
  2         103  
5 2     2   13 use warnings;
  2         5  
  2         137  
6 2     2   11 no warnings qw( once void );
  2         4  
  2         496  
7              
8             our $USES_MITE = "Mite::Class";
9             our $MITE_SHIM = "Type::Library::Compiler::Mite";
10             our $MITE_VERSION = "0.013000";
11              
12             # Mite keywords
13             BEGIN {
14 2     2   12 my ( $SHIM, $CALLER ) =
15             ( "Type::Library::Compiler::Mite", "Type::Library::Compiler" );
16             (
17             *after, *around, *before, *extends, *field,
18             *has, *param, *signature_for, *with
19             )
20 2         4 = do {
21              
22             package Type::Library::Compiler::Mite;
23 2     2   16 no warnings 'redefine';
  2         5  
  2         1571  
24             (
25 0     0   0 sub { $SHIM->HANDLE_after( $CALLER, "class", @_ ) },
26 2     2   12 sub { $SHIM->HANDLE_around( $CALLER, "class", @_ ) },
27 0     0   0 sub { $SHIM->HANDLE_before( $CALLER, "class", @_ ) },
28       0     sub { },
29 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) },
30 10     10   50 sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) },
31 0     0   0 sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) },
32 0     0   0 sub { $SHIM->HANDLE_signature_for( $CALLER, "class", @_ ) },
33 0     0   0 sub { $SHIM->HANDLE_with( $CALLER, @_ ) },
34 2         541 );
35             };
36             }
37              
38             # Mite imports
39             BEGIN {
40 2     2   16 require Scalar::Util;
41 2         7 *STRICT = \&Type::Library::Compiler::Mite::STRICT;
42 2         5 *bare = \&Type::Library::Compiler::Mite::bare;
43 2         18 *blessed = \&Scalar::Util::blessed;
44 2         5 *carp = \&Type::Library::Compiler::Mite::carp;
45 2         4 *confess = \&Type::Library::Compiler::Mite::confess;
46 2         5 *croak = \&Type::Library::Compiler::Mite::croak;
47 2         5 *false = \&Type::Library::Compiler::Mite::false;
48 2         6 *guard = \&Type::Library::Compiler::Mite::guard;
49 2         20 *lazy = \&Type::Library::Compiler::Mite::lazy;
50 2         35 *lock = \&Type::Library::Compiler::Mite::lock;
51 2         5 *ro = \&Type::Library::Compiler::Mite::ro;
52 2         6 *rw = \&Type::Library::Compiler::Mite::rw;
53 2         5 *rwp = \&Type::Library::Compiler::Mite::rwp;
54 2         16 *true = \&Type::Library::Compiler::Mite::true;
55 2         123 *unlock = \&Type::Library::Compiler::Mite::unlock;
56             }
57              
58             # Gather metadata for constructor and destructor
59             sub __META__ {
60 2     2   13 no strict 'refs';
  2         4  
  2         1103  
61 1     1   3 my $class = shift;
62 1   33     8 $class = ref($class) || $class;
63 1         6 my $linear_isa = mro::get_linear_isa($class);
64             return {
65             BUILD => [
66 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         10  
  0         0  
67 1         5 map { "$_\::BUILD" } reverse @$linear_isa
68             ],
69             DEMOLISH => [
70 1 50       2 map { ( *{$_}{CODE} ) ? ( *{$_}{CODE} ) : () }
  1         23  
  0         0  
71 1         5 map { "$_\::DEMOLISH" } @$linear_isa
  1         4  
72             ],
73             HAS_BUILDARGS => $class->can('BUILDARGS'),
74             HAS_FOREIGNBUILDARGS => $class->can('FOREIGNBUILDARGS'),
75             };
76             }
77              
78             # Standard Moose/Moo-style constructor
79             sub new {
80 1 50   1 1 386472 my $class = ref( $_[0] ) ? ref(shift) : shift;
81 1   33     10 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
82 1         5 my $self = bless {}, $class;
83             my $args =
84             $meta->{HAS_BUILDARGS}
85             ? $class->BUILDARGS(@_)
86 1 50       12 : { ( @_ == 1 ) ? %{ $_[0] } : @_ };
  0 50       0  
87 1         4 my $no_build = delete $args->{__no_BUILD__};
88              
89             # Attribute types (type: Map[NonEmptyStr,Object])
90             # has declaration, file lib/Type/Library/Compiler.pm, line 17
91 1         2 do {
92             my $value =
93             exists( $args->{"types"} )
94 1 50       5 ? $args->{"types"}
95             : $self->_build_types;
96 1 50       2 do {
97              
98             package Type::Library::Compiler::Mite;
99 1 50       10 ( ref($value) eq 'HASH' ) and do {
100 1         2 my $ok = 1;
101 1         3 for my $v ( values %{$value} ) {
  1         6  
102             ( $ok = 0, last )
103             unless (
104 9 50       32 do {
105              
106             package Type::Library::Compiler::Mite;
107 2     2   19 use Scalar::Util ();
  2         4  
  2         2678  
108 9         26 Scalar::Util::blessed($v);
109             }
110             );
111             };
112 1         20 for my $k ( keys %{$value} ) {
  1         6  
113             ( $ok = 0, last )
114             unless (
115             (
116 9 50 33     15 do {
117              
118             package Type::Library::Compiler::Mite;
119 9 50       45 defined($k) and do {
120 9 50       56 ref( \$k ) eq 'SCALAR'
121             or ref( \( my $val = $k ) ) eq
122             'SCALAR';
123             }
124             }
125             )
126             && ( length($k) > 0 )
127             );
128             };
129 1         9 $ok;
130             }
131             }
132             or croak "Type check failed in constructor: %s should be %s",
133             "types", "Map[NonEmptyStr,Object]";
134 1         8 $self->{"types"} = $value;
135             };
136              
137             # Attribute pod (type: Bool)
138             # has declaration, file lib/Type/Library/Compiler.pm, line 19
139 1         2 do {
140 1 50       5 my $value = exists( $args->{"pod"} ) ? $args->{"pod"} : true;
141 1         3 do {
142 1         3 my $coerced_value = do {
143 1         2 my $to_coerce = $value;
144             (
145             (
146             !ref $to_coerce
147             and ( !defined $to_coerce
148             or $to_coerce eq q()
149             or $to_coerce eq '0'
150             or $to_coerce eq '1' )
151             )
152             ) ? $to_coerce
153             : ( ( !!1 ) )
154 1 50 33     31 ? scalar( do { local $_ = $to_coerce; !!$_ } )
  0         0  
  0         0  
155             : $to_coerce;
156             };
157             (
158 1 50 33     21 !ref $coerced_value
      33        
159             and ( !defined $coerced_value
160             or $coerced_value eq q()
161             or $coerced_value eq '0'
162             or $coerced_value eq '1' )
163             )
164             or croak "Type check failed in constructor: %s should be %s",
165             "pod", "Bool";
166 1         4 $self->{"pod"} = $coerced_value;
167             };
168             };
169              
170             # Attribute destination_module (type: NonEmptyStr)
171             # has declaration, file lib/Type/Library/Compiler.pm, line 26
172             croak "Missing key in constructor: destination_module"
173 1 50       3 unless exists $args->{"destination_module"};
174             (
175             (
176             do {
177              
178             package Type::Library::Compiler::Mite;
179 1 50       4 defined( $args->{"destination_module"} ) and do {
180             ref( \$args->{"destination_module"} ) eq 'SCALAR'
181 1 50       16 or ref( \( my $val = $args->{"destination_module"} ) )
182             eq 'SCALAR';
183             }
184             }
185             )
186 1 50 33     3 && do {
187              
188             package Type::Library::Compiler::Mite;
189 1         5 length( $args->{"destination_module"} ) > 0;
190             }
191             )
192             or croak "Type check failed in constructor: %s should be %s",
193             "destination_module", "NonEmptyStr";
194 1         4 $self->{"destination_module"} = $args->{"destination_module"};
195              
196             # Attribute constraint_module (type: NonEmptyStr)
197             # has declaration, file lib/Type/Library/Compiler.pm, line 38
198 1         1 do {
199             my $value =
200             exists( $args->{"constraint_module"} )
201 1 50       11 ? $args->{"constraint_module"}
202             : $self->_build_constraint_module;
203             (
204             (
205 1 50 33     11 do {
206              
207             package Type::Library::Compiler::Mite;
208 1 50       4 defined($value) and do {
209 1 50       13 ref( \$value ) eq 'SCALAR'
210             or ref( \( my $val = $value ) ) eq 'SCALAR';
211             }
212             }
213             )
214             && ( length($value) > 0 )
215             )
216             or croak "Type check failed in constructor: %s should be %s",
217             "constraint_module", "NonEmptyStr";
218 1         12 $self->{"constraint_module"} = $value;
219             };
220              
221             # Attribute destination_filename (type: NonEmptyStr)
222             # has declaration, file lib/Type/Library/Compiler.pm, line 47
223 1 50       4 if ( exists $args->{"destination_filename"} ) {
224             (
225             (
226             do {
227              
228             package Type::Library::Compiler::Mite;
229 0 0       0 defined( $args->{"destination_filename"} ) and do {
230             ref( \$args->{"destination_filename"} ) eq 'SCALAR'
231             or ref(
232 0 0       0 \( my $val = $args->{"destination_filename"} ) )
233             eq 'SCALAR';
234             }
235             }
236             )
237 0 0 0     0 && do {
238              
239             package Type::Library::Compiler::Mite;
240 0         0 length( $args->{"destination_filename"} ) > 0;
241             }
242             )
243             or croak "Type check failed in constructor: %s should be %s",
244             "destination_filename", "NonEmptyStr";
245 0         0 $self->{"destination_filename"} = $args->{"destination_filename"};
246             }
247              
248             # Call BUILD methods
249 1 50 33     4 $self->BUILDALL($args) if ( !$no_build and @{ $meta->{BUILD} || [] } );
  1 50       7  
250              
251             # Unrecognized parameters
252             my @unknown = grep not(
253             /\A(?:constraint_module|destination_(?:filename|module)|pod|types)\z/
254 1         2 ), keys %{$args};
  1         14  
255             @unknown
256 1 50       4 and croak(
257             "Unexpected keys in constructor: " . join( q[, ], sort @unknown ) );
258              
259 1         7 return $self;
260             }
261              
262             # Used by constructor to call BUILD methods
263             sub BUILDALL {
264 0     0 0 0 my $class = ref( $_[0] );
265 0   0     0 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
266 0 0       0 $_->(@_) for @{ $meta->{BUILD} || [] };
  0         0  
267             }
268              
269             # Destructor should call DEMOLISH methods
270             sub DESTROY {
271 1     1   38205 my $self = shift;
272 1   33     7 my $class = ref($self) || $self;
273 1   33     6 my $meta = ( $Mite::META{$class} ||= $class->__META__ );
274 1 50       7 my $in_global_destruction =
275             defined ${^GLOBAL_PHASE}
276             ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
277             : Devel::GlobalDestruction::in_global_destruction();
278 1 50       3 for my $demolisher ( @{ $meta->{DEMOLISH} || [] } ) {
  1         6  
279 0         0 my $e = do {
280 0         0 local ( $?, $@ );
281 0         0 eval { $demolisher->( $self, $in_global_destruction ) };
  0         0  
282 0         0 $@;
283             };
284 2     2   19 no warnings 'misc'; # avoid (in cleanup) warnings
  2         4  
  2         2404  
285 0 0       0 die $e if $e; # rethrow
286             }
287 1         20 return;
288             }
289              
290             my $__XS = !$ENV{PERL_ONLY}
291             && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };
292              
293             # Accessors for constraint_module
294             # has declaration, file lib/Type/Library/Compiler.pm, line 38
295             if ($__XS) {
296             Class::XSAccessor->import(
297             chained => 1,
298             "getters" => { "constraint_module" => "constraint_module" },
299             );
300             }
301             else {
302             *constraint_module = sub {
303             @_ == 1
304             or croak(
305             'Reader "constraint_module" usage: $self->constraint_module()');
306             $_[0]{"constraint_module"};
307             };
308             }
309              
310             # Accessors for destination_filename
311             # has declaration, file lib/Type/Library/Compiler.pm, line 47
312             sub destination_filename {
313 0 0   0 1 0 @_ == 1
314             or croak(
315             'Reader "destination_filename" usage: $self->destination_filename()'
316             );
317             (
318             exists( $_[0]{"destination_filename"} )
319             ? $_[0]{"destination_filename"}
320             : (
321 0 0       0 $_[0]{"destination_filename"} = do {
322 0         0 my $default_value = $_[0]->_build_destination_filename;
323             (
324             (
325 0 0 0     0 do {
326              
327             package Type::Library::Compiler::Mite;
328 0 0       0 defined($default_value) and do {
329 0 0       0 ref( \$default_value ) eq 'SCALAR'
330             or ref( \( my $val = $default_value ) )
331             eq 'SCALAR';
332             }
333             }
334             )
335             && ( length($default_value) > 0 )
336             )
337             or croak(
338             "Type check failed in default: %s should be %s",
339             "destination_filename",
340             "NonEmptyStr"
341             );
342 0         0 $default_value;
343             }
344             )
345             );
346             }
347              
348             # Accessors for destination_module
349             # has declaration, file lib/Type/Library/Compiler.pm, line 26
350             if ($__XS) {
351             Class::XSAccessor->import(
352             chained => 1,
353             "getters" => { "destination_module" => "destination_module" },
354             );
355             }
356             else {
357             *destination_module = sub {
358             @_ == 1
359             or croak(
360             'Reader "destination_module" usage: $self->destination_module()'
361             );
362             $_[0]{"destination_module"};
363             };
364             }
365              
366             # Accessors for pod
367             # has declaration, file lib/Type/Library/Compiler.pm, line 19
368             sub pod {
369             @_ > 1
370             ? do {
371 0           my $value = do {
372 0           my $to_coerce = $_[1];
373             (
374             (
375             !ref $to_coerce
376             and ( !defined $to_coerce
377             or $to_coerce eq q()
378             or $to_coerce eq '0'
379             or $to_coerce eq '1' )
380             )
381             ) ? $to_coerce
382 0 0 0       : ( ( !!1 ) ) ? scalar( do { local $_ = $to_coerce; !!$_ } )
  0            
  0            
383             : $to_coerce;
384             };
385             (
386 0 0 0       !ref $value
      0        
387             and ( !defined $value
388             or $value eq q()
389             or $value eq '0'
390             or $value eq '1' )
391             )
392             or croak( "Type check failed in %s: value should be %s",
393             "accessor", "Bool" );
394 0           $_[0]{"pod"} = $value;
395 0           $_[0];
396             }
397 1 50   1 1 8 : ( $_[0]{"pod"} );
398             }
399              
400             # Accessors for types
401             # has declaration, file lib/Type/Library/Compiler.pm, line 17
402             if ($__XS) {
403             Class::XSAccessor->import(
404             chained => 1,
405             "getters" => { "types" => "types" },
406             );
407             }
408             else {
409             *types = sub {
410             @_ == 1 or croak('Reader "types" usage: $self->types()');
411             $_[0]{"types"};
412             };
413             }
414              
415             # See UNIVERSAL
416             sub DOES {
417 0     0 0   my ( $self, $role ) = @_;
418 0           our %DOES;
419 0 0         return $DOES{$role} if exists $DOES{$role};
420 0 0         return 1 if $role eq __PACKAGE__;
421 0 0 0       if ( $INC{'Moose/Util.pm'}
      0        
422             and my $meta = Moose::Util::find_meta( ref $self or $self ) )
423             {
424 0 0 0       $meta->can('does_role') and $meta->does_role($role) and return 1;
425             }
426 0           return $self->SUPER::DOES($role);
427             }
428              
429             # Alias for Moose/Moo-compatibility
430             sub does {
431 0     0 0   shift->DOES(@_);
432             }
433              
434             1;
435             }