| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::MakeMethods::Emulator::Struct; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9288
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
67
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
2754
|
use Class::MakeMethods; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use vars qw(@ISA @EXPORT); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
1055
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
|
9
|
|
|
|
|
|
|
push @ISA, qw(Exporter); |
|
10
|
|
|
|
|
|
|
@EXPORT = qw(struct); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
|
13
|
5
|
|
|
5
|
|
151
|
my $self = shift; |
|
14
|
|
|
|
|
|
|
|
|
15
|
5
|
100
|
|
|
|
18
|
if ( @_ == 0 ) { |
|
|
|
100
|
|
|
|
|
|
|
16
|
3
|
|
|
|
|
2501
|
$self->export_to_level( 1, $self, @EXPORT ); |
|
17
|
|
|
|
|
|
|
} elsif ( @_ == 1 ) { |
|
18
|
1
|
|
|
|
|
69
|
$self->export_to_level( 1, $self, @_ ); |
|
19
|
|
|
|
|
|
|
} else { |
|
20
|
1
|
|
|
|
|
3
|
&struct; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
######################################################################## |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my %type_map = ( |
|
27
|
|
|
|
|
|
|
'$' => 'scalar', |
|
28
|
|
|
|
|
|
|
'@' => 'array', |
|
29
|
|
|
|
|
|
|
'%' => 'hash', |
|
30
|
|
|
|
|
|
|
'_' => 'object', |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub struct { |
|
34
|
4
|
|
|
4
|
0
|
2124
|
my ($class, @decls); |
|
35
|
4
|
|
|
|
|
11
|
my $base_type = ref $_[1] ; |
|
36
|
4
|
100
|
|
|
|
18
|
if ( $base_type eq 'HASH' ) { |
|
|
|
50
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
4
|
$base_type = 'Standard::Hash'; |
|
38
|
2
|
|
|
|
|
2
|
$class = shift; |
|
39
|
2
|
|
|
|
|
4
|
@decls = %{shift()}; |
|
|
2
|
|
|
|
|
8
|
|
|
40
|
2
|
50
|
|
|
|
9
|
_usage_error() if @_; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif ( $base_type eq 'ARRAY' ) { |
|
43
|
0
|
|
|
|
|
0
|
$base_type = 'Standard::Array'; |
|
44
|
0
|
|
|
|
|
0
|
$class = shift; |
|
45
|
0
|
|
|
|
|
0
|
@decls = @{shift()}; |
|
|
0
|
|
|
|
|
0
|
|
|
46
|
0
|
0
|
|
|
|
0
|
_usage_error() if @_; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
else { |
|
49
|
2
|
|
|
|
|
6
|
$base_type = 'Standard::Array'; |
|
50
|
2
|
|
|
|
|
9
|
$class = (caller())[0]; |
|
51
|
2
|
|
|
|
|
11
|
@decls = @_; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
4
|
50
|
|
|
|
16
|
_usage_error() if @decls % 2 == 1; |
|
54
|
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
6
|
my @rewrite; |
|
56
|
4
|
|
|
|
|
30
|
while ( scalar @decls ) { |
|
57
|
13
|
|
|
|
|
24
|
my ($name, $type) = splice(@decls, 0, 2); |
|
58
|
13
|
100
|
|
|
|
78
|
push @rewrite, $type_map{$type} |
|
59
|
|
|
|
|
|
|
? ( $type_map{$type} => { 'name'=>$name, auto_init=>1 } ) |
|
60
|
|
|
|
|
|
|
: ( $type_map{'_'} => { 'name'=>$name, 'class'=>$type, auto_init=>1 } ); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
Class::MakeMethods->make( |
|
63
|
4
|
|
|
|
|
42
|
-TargetClass => $class, |
|
64
|
|
|
|
|
|
|
-MakerClass => $base_type, |
|
65
|
|
|
|
|
|
|
"new" => 'new', |
|
66
|
|
|
|
|
|
|
@rewrite |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _usage_error { |
|
71
|
0
|
|
|
0
|
|
|
require Carp; |
|
72
|
0
|
|
|
|
|
|
Carp::confess "struct usage error"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
######################################################################## |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |