line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Poet::Environment::Generator; |
2
|
|
|
|
|
|
|
$Poet::Environment::Generator::VERSION = '0.16'; |
3
|
6
|
|
|
6
|
|
25
|
use Cwd qw(realpath); |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
302
|
|
4
|
6
|
|
|
6
|
|
26
|
use File::Find; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
281
|
|
5
|
6
|
|
|
6
|
|
2915
|
use File::ShareDir; |
|
6
|
|
|
|
|
33598
|
|
|
6
|
|
|
|
|
364
|
|
6
|
6
|
|
|
6
|
|
1513
|
use Mason; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Method::Signatures::Simple; |
8
|
|
|
|
|
|
|
use Poet::Tools qw(basename dirname mkpath read_dir trim write_file); |
9
|
|
|
|
|
|
|
use strict; |
10
|
|
|
|
|
|
|
use warnings; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
method generate_environment_directory ($class: %params) { |
13
|
|
|
|
|
|
|
my $root_dir = $params{root_dir} or die "must specify root_dir"; |
14
|
|
|
|
|
|
|
my $app_name = $params{app_name} || basename($root_dir); |
15
|
|
|
|
|
|
|
my $quiet = $params{quiet}; |
16
|
|
|
|
|
|
|
my $style = $params{style} || 'standard'; |
17
|
|
|
|
|
|
|
my $msg = sub { |
18
|
|
|
|
|
|
|
print "$_[0]\n" unless $quiet; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
die "invalid app_name '$app_name' - must be a valid Perl identifier" |
22
|
|
|
|
|
|
|
unless $app_name =~ qr/[[:alpha:]_]\w*/; |
23
|
|
|
|
|
|
|
die "cannot generate environment in $root_dir - directory exists and is non-empty" |
24
|
|
|
|
|
|
|
if ( -d $root_dir && @{ read_dir($root_dir) } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $share_dir = realpath( $ENV{POET_SHARE_DIR} || File::ShareDir::dist_dir('Poet') ); |
27
|
|
|
|
|
|
|
die "cannot find Poet share dir '$share_dir'" unless -d $share_dir; |
28
|
|
|
|
|
|
|
my $comp_root = "$share_dir/generate.skel"; |
29
|
|
|
|
|
|
|
my $interp = Mason->new( |
30
|
|
|
|
|
|
|
comp_root => $comp_root, |
31
|
|
|
|
|
|
|
autoextend_request_path => 0, |
32
|
|
|
|
|
|
|
top_level_regex => qr/./, |
33
|
|
|
|
|
|
|
allow_globals => [qw($app_name $root_dir)], |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
$interp->set_global( '$app_name' => $app_name ); |
36
|
|
|
|
|
|
|
$interp->set_global( '$root_dir' => $root_dir ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @paths = $interp->all_paths() |
39
|
|
|
|
|
|
|
or die "could not find template components"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
foreach my $path (@paths) { |
42
|
|
|
|
|
|
|
next if $path =~ m{/\.}; # .svn, .git, etc. |
43
|
|
|
|
|
|
|
my $output = trim( $interp->run($path)->output ); |
44
|
|
|
|
|
|
|
( my $dest = $path ) =~ s{/DOT_}{/.}g; |
45
|
|
|
|
|
|
|
$dest = $root_dir . $dest; |
46
|
|
|
|
|
|
|
$dest =~ s|$root_dir/lib/MyApp|$root_dir/lib/$app_name|; |
47
|
|
|
|
|
|
|
mkpath( dirname($dest), 0, 0775 ); |
48
|
|
|
|
|
|
|
if ( $path =~ /EMPTY$/ ) { |
49
|
|
|
|
|
|
|
$msg->( dirname($dest) ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
$msg->($dest); |
53
|
|
|
|
|
|
|
write_file( $dest, $output ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
find( sub { chmod( 0775, $_ ) if /\.pl$/ }, $root_dir ); |
58
|
|
|
|
|
|
|
$msg->("\nNow run '$root_dir/bin/run.pl' to start your server."); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $root_dir; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |