| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::GenSource; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-06-12'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
19255
|
use 5.010001; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
39
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
600
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#use Data::Dumper; |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
#sub _dump { |
|
13
|
|
|
|
|
|
|
# local $Data::Dumper::Sortkeys = 1; |
|
14
|
|
|
|
|
|
|
# local $Data::Dumper::Indent = 0; |
|
15
|
|
|
|
|
|
|
# local $Data::Dumper::Terse = 1; |
|
16
|
|
|
|
|
|
|
# local $Data::Dumper::Deparse = 1; |
|
17
|
|
|
|
|
|
|
# Dumper($_[0]); |
|
18
|
|
|
|
|
|
|
#} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Exporter; |
|
21
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = qw(gen_class_source_code); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our %SPEC; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $re_ident = qr/\A[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z_][A-Za-z0-9_]*)*\z/; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$SPEC{gen_class_source_code} = { |
|
29
|
|
|
|
|
|
|
v => 1.1, |
|
30
|
|
|
|
|
|
|
summary => 'Generate Perl source code to declare a class', |
|
31
|
|
|
|
|
|
|
description => <<'_', |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
_ |
|
34
|
|
|
|
|
|
|
args => { |
|
35
|
|
|
|
|
|
|
name => { |
|
36
|
|
|
|
|
|
|
schema => ['str*', match=>$re_ident], |
|
37
|
|
|
|
|
|
|
req => 1, |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
parent => { |
|
40
|
|
|
|
|
|
|
schema => ['str*', match=>$re_ident], |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
attributes => { |
|
43
|
|
|
|
|
|
|
schema => ['hash*', match=>$re_ident], |
|
44
|
|
|
|
|
|
|
default => {}, |
|
45
|
|
|
|
|
|
|
}, |
|
46
|
|
|
|
|
|
|
variant => { |
|
47
|
|
|
|
|
|
|
schema => ['str*', in=>[qw/classic Mo Moo Moose Mouse Mojo::Base/]], |
|
48
|
|
|
|
|
|
|
default => 'classic', |
|
49
|
|
|
|
|
|
|
}, |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
result_naked => 1, |
|
52
|
|
|
|
|
|
|
}; |
|
53
|
|
|
|
|
|
|
sub gen_class_source_code { |
|
54
|
2
|
|
|
2
|
1
|
4253
|
my %args = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# XXX schema |
|
57
|
2
|
|
100
|
|
|
10
|
my $variant = $args{variant} // 'classic'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
2
|
my @res; |
|
60
|
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
6
|
push @res, "package $args{name};\n"; |
|
62
|
2
|
50
|
|
|
|
5
|
if ($variant eq 'Mojo::Base') { |
|
63
|
0
|
0
|
|
|
|
0
|
push @res, "use $variant ", |
|
64
|
|
|
|
|
|
|
($args{parent} ? "'$args{parent}'" : "-base"), ";\n"; |
|
65
|
2
|
100
|
|
|
|
11
|
} if ($variant =~ /^(Mo|Moo|Moose|Mouse)$/) { |
|
66
|
1
|
|
|
|
|
2
|
push @res, "use $variant;\n"; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
2
|
50
|
|
|
|
4
|
if ($args{parent}) { |
|
70
|
0
|
0
|
|
|
|
0
|
if ($variant =~ /^(Mo|Moo|Moose|Mouse)$/) { |
|
|
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
push @res, "extends '$args{parent}';\n"; |
|
72
|
|
|
|
|
|
|
} elsif ($variant eq 'classic') { |
|
73
|
0
|
|
|
|
|
0
|
push @res, "use parent qw(", $args{parent}, ");\n"; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
100
|
|
|
|
6
|
if ($variant eq 'classic') { |
|
78
|
1
|
|
|
|
|
2
|
push @res, q[sub new { my $class = shift; bless {@_}, $class; }], "\n"; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
2
|
|
50
|
|
|
5
|
my $attrs = $args{attributes} // {}; |
|
82
|
2
|
|
|
|
|
10
|
for my $name (sort keys %$attrs) { |
|
83
|
4
|
50
|
|
|
|
14
|
if ($variant =~ /^(Mojo::Base)$/) { |
|
|
|
100
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
push @res, "has '$name';\n"; |
|
85
|
|
|
|
|
|
|
} elsif ($variant =~ /^(Mo|Moo|Moose|Mouse)$/) { |
|
86
|
2
|
|
|
|
|
3
|
push @res, "has $name => (is=>'rw');\n"; |
|
87
|
|
|
|
|
|
|
} else { |
|
88
|
2
|
|
|
|
|
5
|
push @res, "sub $name { my \$self = shift; \$self->{'$name'} = \$_[0] if \@_; \$self->{'$name'} }\n"; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
9
|
join("", @res); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
# ABSTRACT: Generate Perl source code to declare a class |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |