File Coverage

blib/lib/Mite/Compiled.pm
Criterion Covered Total %
statement 35 38 92.1
branch 3 6 50.0
condition 5 9 55.5
subroutine 8 8 100.0
pod 0 3 0.0
total 51 64 79.6


line stmt bran cond sub pod time code
1 107     107   2374 use 5.010001;
  107         446  
2 107     107   11515 use strict;
  107         274  
  107         2695  
3 107     107   590 use warnings;
  107         790  
  107         4939  
4              
5             use Mite::Miteception -all;
6 107     107   764  
  107         336  
  107         1089  
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.011000';
9              
10             use Path::Tiny;
11 107     107   814  
  107         248  
  107         63430  
12             # Don't load Mite::Source else it will go circular
13              
14             has file =>
15             is => rw,
16             isa => Path,
17             coerce => true,
18             lazy => true,
19             default => sub {
20             my $self = shift;
21             return $self->_source_file2compiled_file( $self->source->file );
22             };
23              
24             has source =>
25             is => ro,
26             isa => MiteSource,
27             # avoid a circular dep with Mite::Source
28             weak_ref => true,
29             required => true,
30             handles => [ qw( classes class_order ) ];
31              
32             my $self = shift;
33              
34 88     88 0 237 my $code;
35             for my $class_name ( @{ $self->class_order } ) {
36 88         207 my $class = $self->classes->{$class_name};
37 88         234  
  88         500  
38 122         622 # Only supported by Type::Tiny 1.013_001 but no harm
39             # in doing this anyway.
40             local $Type::Tiny::SafePackage = sprintf 'package %s;',
41             eval { $self->source->project->config->data->{shim} }
42             // do { $class_name . '::__SAFE_NAMESPACE__' };
43 122         758  
44 122   66     388 $code .= $class->compile;
  116         4626  
45             }
46 122         1288  
47             my $tidied;
48             eval {
49 88         322 my $flag;
50 88 50 66     252 if ( $self->source->project->config->should_tidy ) {
      33        
51 88         180 $flag = Perl::Tidy::perltidy(
52 88 50       701 source => \$code,
53 0         0 destination => \$tidied,
54             argv => [],
55             );
56             }
57             !$flag;
58             } and defined($tidied) and length($tidied) and ($code = $tidied);
59 6         45  
60             return $code;
61             }
62 88         2700  
63             my ( $self, %opts ) = @_;
64              
65             my $code = $self->compile;
66 88     88 0 502 if ( defined $opts{module_fakeout_namespace} ) {
67             my $ns = $opts{module_fakeout_namespace};
68 88         523 $code =~ s/$ns\:://g;
69 88 50       431 }
70 0         0  
71 0         0 return $self->file->spew_utf8($code);
72             }
73              
74 88         554 my $self = shift;
75              
76             return $self->file->remove;
77             }
78 1     1 0 7  
79             signature_for _source_file2compiled_file => (
80 1         4 pos => [ Defined ],
81             );
82              
83             my ( $self, $source_file ) = @_;
84              
85             # Changes here must be coordinated with Mite.pm
86             return $source_file . '.mite.pm';
87             }
88              
89             1;