| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package MooseX::Compile::CLI::Command::compile; | ||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Path::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | extends qw( | ||||||||||||||||||||||||||||
| 9 | MooseX::Compile::Base | ||||||||||||||||||||||||||||
| 10 | MooseX::Compile::CLI::Base | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | has compiler_class => ( | ||||||||||||||||||||||||||||
| 14 | documentation => "The compiler class to use", | ||||||||||||||||||||||||||||
| 15 | isa => "Str", | ||||||||||||||||||||||||||||
| 16 | is => "rw", | ||||||||||||||||||||||||||||
| 17 | default => "MooseX::Compile::Compiler", | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has compiler_args => ( | ||||||||||||||||||||||||||||
| 21 | documentation => "Additional arguments for the compiler", | ||||||||||||||||||||||||||||
| 22 | isa => "ArrayRef", | ||||||||||||||||||||||||||||
| 23 | is => "rw", | ||||||||||||||||||||||||||||
| 24 | auto_deref => 1, | ||||||||||||||||||||||||||||
| 25 | default => sub { [] }, | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | has compiler => ( | ||||||||||||||||||||||||||||
| 29 | metaclass => "NoGetopt", | ||||||||||||||||||||||||||||
| 30 | isa => "Object", | ||||||||||||||||||||||||||||
| 31 | is => "rw", | ||||||||||||||||||||||||||||
| 32 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has target_lib => ( | ||||||||||||||||||||||||||||
| 36 | documentation => "If supplied .pmcs will be written to this lib directory, instead of next to where the original .pm files are", | ||||||||||||||||||||||||||||
| 37 | metaclass => "Getopt", | ||||||||||||||||||||||||||||
| 38 | cmd_aliases => ["C"], | ||||||||||||||||||||||||||||
| 39 | isa => "Str", | ||||||||||||||||||||||||||||
| 40 | is => "rw", | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub _build_compiler { | ||||||||||||||||||||||||||
|
Subroutine
_build_compiler: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my $class = $self->compiler_class; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | $self->load_classes( $class ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $class->new( $self->compiler_args ); | |||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | augment run => sub { | ||||||||||||||||||||||||||||
| 54 | my ( $self, $opts, $args ) = @_; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | $self->compile_all_classes; | ||||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | augment build_from_opts => sub { | ||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub compile_all_classes { | ||||||||||||||||||||||||||
|
Subroutine
compile_all_classes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $self->compile_classes( $self->all_files ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub compile_classes { | ||||||||||||||||||||||||||
|
Subroutine
compile_classes: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 69 | 0 | my ( $self, @files ) = @_; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my %seen_out; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | file: foreach my $file ( @files ) { | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( my $seen = $seen_out{$file->{pmc_file}} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | warn "Class '$file->{class}' found in '$seen->{dir}' was already compiled into '$file->{pmc_file}', skipping the version in '$file->{dir}'\n" if $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | next file; | |||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||
| 78 | 0 | $seen_out{$file->{pmc_file}} = $file; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | $self->compile_class($file); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub compile_class { | ||||||||||||||||||||||||||
|
Subroutine
compile_class: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 86 | 0 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # FIXME use $^X and a simpler compilation command? | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( my $pid = fork ) { # clean env to load the module in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | waitpid $pid, 0; | |||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | warn "Compiling class '$file->{class}'\n" if $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | local @INC = ( "$file->{dir}", @INC ); | |||||||||||||||||||||||||||
| 96 | 0 | require $file->{rel}; | |||||||||||||||||||||||||||
| 97 | } ) { | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( eval { $file->{class}->meta->isa("Moose::Meta::Class") } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $self->compiler->compile_class( %$file ); | |||||||||||||||||||||||||||
| 100 | 0 | warn "Compiled '$file->{class}' from '$file->{dir}' into " . $file->{pmc_file}->relative($file->{dir}) . "\n"; | |||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | warn "Skipping $file->{class}, it's not a Moose class\n" if $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||
| 105 | 0 | my $f = quotemeta(__FILE__); | |||||||||||||||||||||||||||
| 106 | 0 | ( my $e = $@ ) =~ s/ at $f line \d+\.\n$/./s; | |||||||||||||||||||||||||||
| 107 | 0 | warn "Loading of file '$file->{rel}' from '$file->{dir}' failed: $e\n"; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | exit; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub filter_file { | ||||||||||||||||||||||||||
|
Subroutine
filter_file: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 115 | 0 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return $file if $file->basename =~ m/\.pm$/ and -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file->basename =~ /\.pm$/ and -f $file
MC/DC0%0/2
$file->basename =~ /\.pm$/ and -f $file
$file->basename =~ /\.pm$/
-f $file
Truth table0%0/3
A and B
A= $file->basename =~ /\.pm$/B= -f $file
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | return; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | override file_in_dir => sub { | ||||||||||||||||||||||||||||
| 123 | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | my $entry = super(); | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | my ( $rel, $dir ) = @{ $entry }{qw(rel dir)}; | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | $entry->{pmc_file} = file( "${rel}c" )->absolute( dir( $self->target_lib || $dir ) ); | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | return $entry; | ||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | __PACKAGE__ | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||