| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::mgen; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1126
|
use 5.008; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
92
|
|
|
4
|
2
|
|
|
2
|
|
1996
|
use utf8; |
|
|
2
|
|
|
|
|
21
|
|
|
|
2
|
|
|
|
|
12
|
|
|
5
|
2
|
|
|
2
|
|
69
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
119
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use Cwd; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
168
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use Carp (); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
29
|
|
|
10
|
2
|
|
|
2
|
|
1805
|
use IO::File; |
|
|
2
|
|
|
|
|
23365
|
|
|
|
2
|
|
|
|
|
293
|
|
|
11
|
2
|
|
|
2
|
|
20
|
use List::Util; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
149
|
|
|
12
|
2
|
|
|
2
|
|
11
|
use File::Path; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
121
|
|
|
13
|
2
|
|
|
2
|
|
266394
|
use Pod::Usage; |
|
|
2
|
|
|
|
|
324355
|
|
|
|
2
|
|
|
|
|
342
|
|
|
14
|
2
|
|
|
2
|
|
364946
|
use Time::Piece; |
|
|
2
|
|
|
|
|
21681
|
|
|
|
2
|
|
|
|
|
10
|
|
|
15
|
2
|
|
|
2
|
|
2390
|
use Getopt::Long; |
|
|
2
|
|
|
|
|
23315
|
|
|
|
2
|
|
|
|
|
13
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
2
|
|
|
2
|
0
|
1151
|
my $class = shift; |
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
53
|
my $self = bless { |
|
21
|
|
|
|
|
|
|
options => { |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# option list |
|
24
|
|
|
|
|
|
|
moose => undef, |
|
25
|
|
|
|
|
|
|
mouse => undef, |
|
26
|
|
|
|
|
|
|
moo => undef, |
|
27
|
|
|
|
|
|
|
mo => undef, |
|
28
|
|
|
|
|
|
|
m => undef, |
|
29
|
|
|
|
|
|
|
immutable => undef, |
|
30
|
|
|
|
|
|
|
autoclearn => undef, |
|
31
|
|
|
|
|
|
|
signature => undef, |
|
32
|
|
|
|
|
|
|
silent => undef, |
|
33
|
|
|
|
|
|
|
dryrun => undef, |
|
34
|
|
|
|
|
|
|
description => undef, |
|
35
|
|
|
|
|
|
|
author => undef, |
|
36
|
|
|
|
|
|
|
email => undef, |
|
37
|
|
|
|
|
|
|
path => undef, |
|
38
|
|
|
|
|
|
|
current => undef, |
|
39
|
|
|
|
|
|
|
}, |
|
40
|
|
|
|
|
|
|
description => "", |
|
41
|
|
|
|
|
|
|
module_name => "", |
|
42
|
|
|
|
|
|
|
module_path => "", |
|
43
|
|
|
|
|
|
|
author => "", |
|
44
|
|
|
|
|
|
|
email => "", |
|
45
|
|
|
|
|
|
|
}, $class; |
|
46
|
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
25
|
return $self->_set_env->_set_options; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub generate { |
|
51
|
1
|
|
|
1
|
0
|
432
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## code generate |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# set header |
|
56
|
1
|
|
|
|
|
5
|
my $gen = $self->_gen_default; |
|
57
|
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
4
|
for my $attribute (qw/signature moose autoclearn immutable mouse moo mo m/) { |
|
59
|
8
|
|
|
|
|
10
|
my $call = "_gen_$attribute"; |
|
60
|
8
|
50
|
|
|
|
23
|
$gen .= $self->$call if defined($self->{options}->{$attribute}); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# set footer |
|
64
|
1
|
|
|
|
|
5
|
$gen .= $self->_gen_packend . $self->_gen_pod; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
## file output |
|
67
|
1
|
|
|
|
|
2
|
my $path; |
|
68
|
1
|
50
|
|
|
|
5
|
if ( !$self->{options}->{dryrun} ) { |
|
69
|
0
|
0
|
|
|
|
0
|
if ( !$self->{options}->{current} ) { |
|
70
|
0
|
0
|
|
|
|
0
|
$path = $self->_create_dir if !$self->{options}->{current}; |
|
71
|
|
|
|
|
|
|
} else { |
|
72
|
0
|
|
|
|
|
0
|
my @depth = split "::", $self->{module_name}; |
|
73
|
0
|
|
|
|
|
0
|
$path = pop @depth; |
|
74
|
0
|
|
|
|
|
0
|
$path = sprintf "%s.pm", $path; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
0
|
my $io = IO::File->new( $path, "w" ) || die $!; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
$io->print($gen); |
|
80
|
0
|
|
|
|
|
0
|
$io->close; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
## std output |
|
84
|
1
|
50
|
|
|
|
6
|
if ( !$self->{options}->{silent} ) { |
|
85
|
1
|
|
|
|
|
1304
|
print "$gen\n"; |
|
86
|
1
|
50
|
|
|
|
7
|
print "OUTPUT >> $path\n" if $path; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
12
|
return $gen; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _set_env { |
|
93
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
2
|
50
|
|
|
|
20
|
$self->{module_path} = $ENV{MGEN_ROOT} ? $ENV{MGEN_ROOT} : ""; |
|
96
|
2
|
50
|
|
|
|
12
|
$self->{author} = $ENV{MGEN_AUTHOR} ? $ENV{MGEN_AUTHOR} : ""; |
|
97
|
2
|
50
|
|
|
|
12
|
$self->{email} = $ENV{MGEN_EMAIL} ? $ENV{MGEN_EMAIL} : ""; |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
18
|
return $self; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _set_options { |
|
103
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Set options |
|
106
|
2
|
|
|
|
|
6
|
my $options = {}; |
|
107
|
2
|
|
|
|
|
37
|
my $ret = GetOptions( |
|
108
|
|
|
|
|
|
|
'moose' => \( $options->{moose} ), |
|
109
|
|
|
|
|
|
|
'mouse' => \( $options->{mouse} ), |
|
110
|
|
|
|
|
|
|
'moo' => \( $options->{moo} ), |
|
111
|
|
|
|
|
|
|
'mo' => \( $options->{mo} ), |
|
112
|
|
|
|
|
|
|
'm' => \( $options->{m} ), |
|
113
|
|
|
|
|
|
|
'immutable' => \( $options->{immutable} ), |
|
114
|
|
|
|
|
|
|
'autoclearn' => \( $options->{autoclearn} ), |
|
115
|
|
|
|
|
|
|
'signature' => \( $options->{signature} ), |
|
116
|
|
|
|
|
|
|
'silent' => \( $options->{silent} ), |
|
117
|
|
|
|
|
|
|
'dry-run' => \( $options->{dryrun} ), |
|
118
|
|
|
|
|
|
|
'description=s' => \( $options->{description} ), |
|
119
|
|
|
|
|
|
|
'author=s' => \( $options->{author} ), |
|
120
|
|
|
|
|
|
|
'email=s' => \( $options->{email} ), |
|
121
|
|
|
|
|
|
|
'path=s' => \( $options->{path} ), |
|
122
|
|
|
|
|
|
|
'current' => \( $options->{current} ), |
|
123
|
|
|
|
|
|
|
help => \&__pod2usage, |
|
124
|
|
|
|
|
|
|
version => \&__version |
|
125
|
|
|
|
|
|
|
); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Set members |
|
128
|
2
|
|
|
|
|
1825
|
$self->{options} = $options; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Set module name |
|
131
|
2
|
50
|
|
|
|
14
|
&__pod2usage unless @ARGV; |
|
132
|
2
|
|
|
|
|
5
|
$self->{module_name} = pop @ARGV; |
|
133
|
2
|
|
|
|
|
7
|
$self->{module_name} =~ s/\.pm$//g; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Set description |
|
136
|
2
|
50
|
|
|
|
11
|
$self->{description} = $self->{options}->{description} |
|
137
|
|
|
|
|
|
|
if $self->{options}->{description}; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Set user status |
|
140
|
2
|
50
|
|
|
|
12
|
$self->{author} = |
|
|
|
50
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$self->{options}->{author} ? $self->{options}->{author} |
|
142
|
|
|
|
|
|
|
: $self->{author} ? $self->{author} |
|
143
|
|
|
|
|
|
|
: undef; |
|
144
|
2
|
50
|
|
|
|
21
|
$self->{email} = |
|
|
|
50
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$self->{options}->{email} ? $self->{options}->{email} |
|
146
|
|
|
|
|
|
|
: $self->{email} ? $self->{email} |
|
147
|
|
|
|
|
|
|
: undef; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# If not exist path, set current directory. It is deprecated. |
|
150
|
2
|
50
|
|
|
|
26
|
$self->{module_path} = getcwd if !$self->{module_path}; |
|
151
|
2
|
50
|
|
|
|
10
|
$self->{module_path} = $self->{options}->{path} if $self->{options}->{path}; |
|
152
|
|
|
|
|
|
|
|
|
153
|
2
|
|
|
|
|
7
|
return $self; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub _create_dir { |
|
157
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
0
|
return if !$self->{module_path}; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
my $module_name = $self->{module_name}; |
|
162
|
0
|
|
|
|
|
0
|
$module_name =~ s/::/\//g; |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
my ( $path, $file_path ); |
|
165
|
0
|
|
|
|
|
0
|
$path = $file_path = sprintf "%s/%s", $self->{module_path}, $module_name; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
0
|
$path =~ s/\/\///g; # remove duplicates |
|
168
|
0
|
|
|
|
|
0
|
$path =~ s/\/\w+$//g; # remove module name |
|
169
|
0
|
|
|
|
|
0
|
$_ =~ s/[\r\n]//g for ( $path, $file_path ); |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
0
|
eval { mkpath($path); }; |
|
|
0
|
|
|
|
|
0
|
|
|
172
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
173
|
0
|
|
|
|
|
0
|
Carp::croak "failed create directory : $@\n"; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
0
|
return "$file_path.pm"; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _gen_pod { |
|
180
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
181
|
|
|
|
|
|
|
|
|
182
|
1
|
|
|
|
|
5
|
my $name = $self->_gen_name; |
|
183
|
1
|
|
|
|
|
7
|
my $author = $self->_gen_author; |
|
184
|
1
|
|
|
|
|
6
|
my $description = $self->_gen_description; |
|
185
|
|
|
|
|
|
|
|
|
186
|
1
|
|
|
|
|
6
|
my $pod = <<"GEN_POD"; |
|
187
|
|
|
|
|
|
|
__END__ |