| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::MyPerl::Role::Script; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
31316
|
use File::Spec; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
76
|
|
|
4
|
3
|
|
|
3
|
|
15
|
use IO::All; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
23
|
|
|
5
|
3
|
|
|
3
|
|
154
|
use Moo::Role; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $ioify = sub { |
|
8
|
|
|
|
|
|
|
(defined($_[0]) and not ref($_[0])) |
|
9
|
|
|
|
|
|
|
? io->dir($_[0]) |
|
10
|
|
|
|
|
|
|
: $_[0] |
|
11
|
|
|
|
|
|
|
}; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
requires 'run'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
453
|
has env_prefix => (is => 'lazy', builder => sub { 'MYPERL' }); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _env_value { |
|
18
|
4
|
|
|
4
|
|
6
|
my ($self, $name) = @_; |
|
19
|
4
|
|
|
|
|
15
|
$ENV{$self->env_prefix.'_'.$name}; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has env_home => (is => 'lazy', builder => sub { |
|
23
|
2
|
|
|
2
|
|
372
|
shift->_env_value('HOME') |
|
24
|
|
|
|
|
|
|
}); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has env_config => (is => 'lazy', builder => sub { |
|
27
|
2
|
|
|
2
|
|
611
|
shift->_env_value('CONFIG') |
|
28
|
|
|
|
|
|
|
}); |
|
29
|
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
|
568
|
has config_dir_name => (is => 'lazy', builder => sub { '.myperl' }); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has global_config_dir => (is => 'lazy', coerce => $ioify, builder => sub { |
|
33
|
2
|
|
|
2
|
|
1440
|
my ($self) = @_; |
|
34
|
2
|
100
|
|
|
|
7
|
if (my $env = $self->env_home) { |
|
|
|
50
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
4
|
io->dir($env) |
|
36
|
|
|
|
|
|
|
} elsif ($env = $ENV{HOME}) { |
|
37
|
1
|
|
|
|
|
4
|
io->dir($env)->catdir($self->config_dir_name) |
|
38
|
|
|
|
|
|
|
} else { |
|
39
|
|
|
|
|
|
|
undef |
|
40
|
0
|
|
|
|
|
0
|
} |
|
41
|
|
|
|
|
|
|
}); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has global_default_config_dir => (is => 'lazy', builder => sub { |
|
44
|
6
|
|
|
6
|
|
2211
|
shift->global_config_dir->catdir('defaults') |
|
45
|
|
|
|
|
|
|
}); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has global_always_config_dir => (is => 'lazy', builder => sub { |
|
48
|
6
|
|
|
6
|
|
914
|
shift->global_config_dir->catdir('always') |
|
49
|
|
|
|
|
|
|
}); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has project_config_dir => (is => 'lazy', coerce => $ioify, builder => sub { |
|
52
|
2
|
|
|
2
|
|
3450
|
my ($self) = @_; |
|
53
|
2
|
|
66
|
|
|
10
|
io->dir($self->env_config || $self->config_dir_name) |
|
54
|
|
|
|
|
|
|
}); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has final_project_config_dir => (is => 'lazy', builder => sub { |
|
57
|
6
|
|
|
6
|
|
3245
|
my ($self) = @_; |
|
58
|
6
|
|
66
|
|
|
28
|
(grep defined && $_->is_executable, |
|
59
|
|
|
|
|
|
|
$self->project_config_dir, $self->global_default_config_dir)[0] |
|
60
|
|
|
|
|
|
|
}); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has config_dirs => (is => 'lazy', builder => sub { |
|
63
|
6
|
|
|
6
|
|
896
|
my ($self) = @_; |
|
64
|
6
|
|
66
|
|
|
24
|
[ grep defined && $_->is_executable, |
|
65
|
|
|
|
|
|
|
$self->global_always_config_dir, $self->final_project_config_dir ] |
|
66
|
|
|
|
|
|
|
}); |
|
67
|
|
|
|
|
|
|
|
|
68
|
6
|
|
|
6
|
0
|
40
|
sub use_files { qw(dev-modules modules) } |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _files_for { |
|
71
|
12
|
|
|
12
|
|
3223
|
my ($self, $dir, $prefix) = @_; |
|
72
|
12
|
|
|
|
|
44
|
map $dir->catfile($prefix.$_), $self->use_files |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _build_module_list { |
|
76
|
8
|
|
|
8
|
|
17
|
my ($self, $prefix) = @_; |
|
77
|
8
|
|
|
|
|
32
|
[ grep !/^#/ && !/^\s*$/, |
|
78
|
|
|
|
|
|
|
map $_->chomp->slurp, |
|
79
|
|
|
|
|
|
|
grep $_->exists, |
|
80
|
|
|
|
|
|
|
map $self->_files_for($_, $prefix), |
|
81
|
8
|
|
33
|
|
|
15
|
@{$self->config_dirs} |
|
82
|
|
|
|
|
|
|
] |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has modules => (is => 'lazy', builder => sub { |
|
86
|
6
|
|
|
6
|
|
1833
|
$_[0]->_build_module_list('') |
|
87
|
|
|
|
|
|
|
}); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has script_modules => (is => 'lazy', builder => sub { |
|
90
|
2
|
|
|
2
|
|
413
|
$_[0]->_build_module_list('script-') |
|
91
|
|
|
|
|
|
|
}); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has preamble => (is => 'lazy', builder => sub { |
|
94
|
2
|
|
|
2
|
|
563
|
$_[0]->_preamble_from_modules(@{$_[0]->modules}) |
|
|
2
|
|
|
|
|
8
|
|
|
95
|
|
|
|
|
|
|
}); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _preamble_from_modules { |
|
98
|
3
|
|
|
3
|
|
2212
|
my ($self, @modules) = @_; |
|
99
|
5
|
|
|
|
|
13
|
[ map { |
|
100
|
3
|
|
|
|
|
6
|
my ($mod, $arg) = split('=', $_, 2); |
|
101
|
5
|
|
|
|
|
8
|
my $use_or_no = "use"; |
|
102
|
5
|
50
|
|
|
|
10
|
if ($mod =~ /^-/) { |
|
103
|
0
|
|
|
|
|
0
|
$use_or_no = "no"; |
|
104
|
0
|
|
|
|
|
0
|
$mod =~ s/^-//; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
5
|
100
|
|
|
|
48
|
($arg |
|
107
|
|
|
|
|
|
|
? "$use_or_no ${mod} qw(".join(' ', split ',', $arg).");" |
|
108
|
|
|
|
|
|
|
: "$use_or_no ${mod};") |
|
109
|
|
|
|
|
|
|
} @modules |
|
110
|
|
|
|
|
|
|
] |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
has perl_options => (is => 'lazy', builder => sub { |
|
114
|
1
|
|
|
1
|
|
739
|
my ($self) = @_; |
|
115
|
|
|
|
|
|
|
[ |
|
116
|
1
|
|
|
|
|
2
|
"-Mlib::with::preamble=${\join(' ', @{$self->preamble})},lib,t/lib", |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
4
|
|
|
117
|
1
|
|
|
|
|
3
|
(map "-M$_", @{$self->script_modules}, @{$self->modules}) |
|
|
1
|
|
|
|
|
599
|
|
|
118
|
|
|
|
|
|
|
]; |
|
119
|
|
|
|
|
|
|
}); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub run_if_script { |
|
122
|
0
|
0
|
|
0
|
0
|
|
return 1 if caller(1); |
|
123
|
0
|
|
|
|
|
|
shift->new->run; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |