line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package classes::Test; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Test.pm 147 2008-03-08 16:04:33Z rmuhle $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# these two are just really brain dead |
6
|
|
|
|
|
|
|
# when using more advanced perl stuff |
7
|
3
|
|
|
3
|
|
21409
|
no strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
106
|
|
8
|
3
|
|
|
3
|
|
16
|
no warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
111
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
16
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
235
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
16
|
use base 'Exporter'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
514
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
can_new |
15
|
|
|
|
|
|
|
can_set_get |
16
|
|
|
|
|
|
|
has_decl |
17
|
|
|
|
|
|
|
has_class_const |
18
|
|
|
|
|
|
|
has_mixins |
19
|
|
|
|
|
|
|
has_mixins_hash |
20
|
|
|
|
|
|
|
is_classes |
21
|
|
|
|
|
|
|
is_throwable |
22
|
|
|
|
|
|
|
is_classes_exc |
23
|
|
|
|
|
|
|
has_tree |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [qw( |
27
|
|
|
|
|
|
|
can_new |
28
|
|
|
|
|
|
|
can_set_get |
29
|
|
|
|
|
|
|
has_decl |
30
|
|
|
|
|
|
|
has_class_const |
31
|
|
|
|
|
|
|
has_mixins |
32
|
|
|
|
|
|
|
has_mixins_hash |
33
|
|
|
|
|
|
|
is_classes |
34
|
|
|
|
|
|
|
is_throwable |
35
|
|
|
|
|
|
|
is_classes_exc |
36
|
|
|
|
|
|
|
)]); |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
3
|
|
17
|
use Test::Builder; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
69
|
|
39
|
3
|
|
|
3
|
|
14
|
use Test::More; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
22
|
|
40
|
|
|
|
|
|
|
my $t = Test::Builder->new(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub can_new (*) { |
43
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
44
|
0
|
|
0
|
|
|
|
return $t->ok( |
45
|
|
|
|
|
|
|
$this->can('new'), |
46
|
|
|
|
|
|
|
"'$this' has new constructor method" |
47
|
|
|
|
|
|
|
) || |
48
|
|
|
|
|
|
|
$t->diag( |
49
|
|
|
|
|
|
|
" '$this' missing new constructor" |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub can_set_get (*) { |
54
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
55
|
0
|
|
0
|
|
|
|
return $t->ok( |
56
|
|
|
|
|
|
|
$this->can('set') |
57
|
|
|
|
|
|
|
&& $this->can('get') |
58
|
|
|
|
|
|
|
, "'$this' can set, get" |
59
|
|
|
|
|
|
|
) || |
60
|
|
|
|
|
|
|
$t->diag(" '$this' missing set, get"); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# should have a DECL hash ref package variable and method |
64
|
|
|
|
|
|
|
sub has_decl (*) { |
65
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
66
|
|
|
|
|
|
|
return $t->ok( |
67
|
|
|
|
|
|
|
$this->can('DECL') && |
68
|
0
|
|
0
|
|
|
|
defined ${$this.'::DECL'}, |
69
|
|
|
|
|
|
|
"'$this' has DECL" |
70
|
|
|
|
|
|
|
) |
71
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not have a DECL declaration"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub has_class_const (*) { |
75
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
76
|
|
|
|
|
|
|
return $t->ok( |
77
|
|
|
|
|
|
|
$this->can('CLASS') && |
78
|
0
|
|
0
|
|
|
|
defined ${$this.'::CLASS'}, |
79
|
|
|
|
|
|
|
"'$this' has CLASS constant" |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not have a CLASS constant"); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub has_mixins (*) { |
85
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
86
|
3
|
|
|
3
|
|
2015
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
352
|
|
87
|
|
|
|
|
|
|
return $t->ok( |
88
|
|
|
|
|
|
|
$this->can('MIXIN') && |
89
|
0
|
|
0
|
|
|
|
scalar %{${$this.'::MIXIN'}}, |
90
|
|
|
|
|
|
|
"'$this' has MIXINs" |
91
|
|
|
|
|
|
|
) |
92
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not have a CLASS constant"); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub has_mixins_hash (*) { |
96
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
97
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1288
|
|
98
|
|
|
|
|
|
|
return $t->ok( |
99
|
|
|
|
|
|
|
$this->can('MIXIN') && |
100
|
0
|
|
0
|
|
|
|
ref ${$this.'::MIXIN'} eq 'HASH', |
101
|
|
|
|
|
|
|
"'$this' has MIXIN hash defined" |
102
|
|
|
|
|
|
|
) |
103
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not have a MIXIN hash"); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub is_classes (*) { |
107
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
108
|
0
|
|
0
|
|
|
|
return $t->ok( |
109
|
|
|
|
|
|
|
can_new($this) && |
110
|
|
|
|
|
|
|
has_class_const($this) && |
111
|
|
|
|
|
|
|
has_decl($this), |
112
|
|
|
|
|
|
|
"'$this' is a classes class" |
113
|
|
|
|
|
|
|
) |
114
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not look like a classes class"); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub is_throwable (*) { |
118
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
119
|
0
|
|
0
|
|
|
|
return $t->ok( |
120
|
|
|
|
|
|
|
$this->can('throw') && |
121
|
|
|
|
|
|
|
$this->can('rethrow') && |
122
|
|
|
|
|
|
|
$this->can('send') && |
123
|
|
|
|
|
|
|
$this->can('catch') && |
124
|
|
|
|
|
|
|
$this->can('caught') && |
125
|
|
|
|
|
|
|
$this->can('capture'), |
126
|
|
|
|
|
|
|
"'$this' fulfills the classes::Throwable interface" |
127
|
|
|
|
|
|
|
) |
128
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not fulfill the classes::Throwable interface"); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub is_classes_exc (*) { |
132
|
0
|
|
0
|
0
|
1
|
|
my $this = blessed $_[0] || $_[0]; |
133
|
0
|
|
0
|
|
|
|
return $t->ok( |
134
|
|
|
|
|
|
|
is_classes($this) && |
135
|
|
|
|
|
|
|
$this->can('as_string') && |
136
|
|
|
|
|
|
|
like( $this->new->as_string, qr/^$this/, |
137
|
|
|
|
|
|
|
'as_string matches' ) && |
138
|
|
|
|
|
|
|
is_throwable($this), |
139
|
|
|
|
|
|
|
"'$this' is a classes::Exception class" |
140
|
|
|
|
|
|
|
) |
141
|
|
|
|
|
|
|
|| $t->diag(" '$this' does not look like a classes::Exception class"); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |