| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package MooseX::Compile::CLI::Command::compile; |
|
4
|
1
|
|
|
1
|
|
11881
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Path::Class; |
|
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
|
|
|
|
|
|
|
sub _build_compiler { |
|
44
|
|
|
|
|
|
|
my $self = shift; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $class = $self->compiler_class; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->load_classes( $class ); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub compile_all_classes { |
|
63
|
|
|
|
|
|
|
my $self = shift; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->compile_classes( $self->all_files ); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub compile_classes { |
|
69
|
|
|
|
|
|
|
my ( $self, @files ) = @_; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my %seen_out; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
file: foreach my $file ( @files ) { |
|
74
|
|
|
|
|
|
|
if ( my $seen = $seen_out{$file->{pmc_file}} ) { |
|
75
|
|
|
|
|
|
|
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; |
|
76
|
|
|
|
|
|
|
next file; |
|
77
|
|
|
|
|
|
|
} else { |
|
78
|
|
|
|
|
|
|
$seen_out{$file->{pmc_file}} = $file; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->compile_class($file); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub compile_class { |
|
86
|
|
|
|
|
|
|
my ( $self, $file ) = @_; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# FIXME use $^X and a simpler compilation command? |
|
89
|
|
|
|
|
|
|
if ( my $pid = fork ) { # clean env to load the module in |
|
90
|
|
|
|
|
|
|
waitpid $pid, 0; |
|
91
|
|
|
|
|
|
|
} else { |
|
92
|
|
|
|
|
|
|
warn "Compiling class '$file->{class}'\n" if $self->verbose; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if ( eval { |
|
95
|
|
|
|
|
|
|
local @INC = ( "$file->{dir}", @INC ); |
|
96
|
|
|
|
|
|
|
require $file->{rel}; |
|
97
|
|
|
|
|
|
|
} ) { |
|
98
|
|
|
|
|
|
|
if ( eval { $file->{class}->meta->isa("Moose::Meta::Class") } ) { |
|
99
|
|
|
|
|
|
|
$self->compiler->compile_class( %$file ); |
|
100
|
|
|
|
|
|
|
warn "Compiled '$file->{class}' from '$file->{dir}' into " . $file->{pmc_file}->relative($file->{dir}) . "\n"; |
|
101
|
|
|
|
|
|
|
} else { |
|
102
|
|
|
|
|
|
|
warn "Skipping $file->{class}, it's not a Moose class\n" if $self->verbose; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} else { |
|
105
|
|
|
|
|
|
|
my $f = quotemeta(__FILE__); |
|
106
|
|
|
|
|
|
|
( my $e = $@ ) =~ s/ at $f line \d+\.\n$/./s; |
|
107
|
|
|
|
|
|
|
warn "Loading of file '$file->{rel}' from '$file->{dir}' failed: $e\n"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
exit; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub filter_file { |
|
115
|
|
|
|
|
|
|
my ( $self, $file ) = @_; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return $file if $file->basename =~ m/\.pm$/ and -f $file; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
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__ |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=pod |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 NAME |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
MooseX::Compile::CLI::Command::compile - Compile Moose classes using MooseX::Compile::Compiler. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# compile My::Class in lib/ |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
> mxcompile compile -l My::Class |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This command is used to compile classes using L<MooseX::Compile::Compiler>. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |