line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Chai::Util::Reflection; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
20
|
use Exporter qw/import/; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
268
|
|
4
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
5
|
|
|
|
|
|
|
add_property |
6
|
|
|
|
|
|
|
add_method |
7
|
|
|
|
|
|
|
add_chainable_method |
8
|
|
|
|
|
|
|
/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub add_property { |
11
|
52
|
|
|
52
|
0
|
88
|
my ($pkg, $name, $code) = @_; |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
20
|
no strict 'refs'; ## no critic |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
490
|
|
14
|
52
|
|
|
|
|
312
|
*{"${pkg}::${name}"} = sub { |
15
|
865
|
|
|
865
|
|
2319
|
my $result = $code->(@_); |
|
|
|
|
865
|
|
|
|
16
|
865
|
100
|
|
|
|
43932
|
return defined $result ? $result : $_[0]; |
17
|
52
|
|
|
|
|
160
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub add_method { |
21
|
72
|
|
|
72
|
0
|
139
|
my ($pkg, $name, $code) = @_; |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
4
|
|
18
|
no strict 'refs'; ## no critic |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
580
|
|
24
|
72
|
|
|
|
|
482
|
*{"${pkg}::${name}"} = sub { |
25
|
257
|
|
|
257
|
|
842
|
my $result = $code->(@_); |
|
|
|
|
257
|
|
|
|
|
|
|
|
257
|
|
|
|
26
|
257
|
100
|
|
|
|
133715
|
return defined $result ? $result : $_[0]; |
27
|
72
|
|
|
|
|
237
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub add_chainable_method { |
31
|
22
|
|
|
22
|
0
|
122
|
my ($pkg, $name, $code, $chaining_behavior) = @_; |
32
|
|
|
|
|
|
|
|
33
|
22
|
100
|
|
|
|
62
|
unless (defined $chaining_behavior) { |
34
|
12
|
|
|
114
|
|
34
|
$chaining_behavior = sub { }; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
22
|
|
|
|
|
65
|
my $chainable_behavior = { |
38
|
|
|
|
|
|
|
method => $code, |
39
|
|
|
|
|
|
|
chaining_behavior => $chaining_behavior, |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
4
|
|
18
|
no strict 'refs'; ## no critic |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
739
|
|
43
|
22
|
50
|
|
|
|
30
|
unless (defined *{"%${pkg}::__methods"}) { |
|
22
|
|
|
|
|
80
|
|
44
|
22
|
|
|
|
|
27
|
*{"${pkg}::__methods"} = {}; |
|
22
|
|
|
|
|
82
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
22
|
|
|
|
|
34
|
*{"${pkg}::__methods"}->{$name} = $chainable_behavior; |
|
22
|
|
|
|
|
75
|
|
48
|
|
|
|
|
|
|
|
49
|
22
|
|
|
|
|
136
|
*{"${pkg}::${name}"} = sub { |
50
|
195
|
|
|
195
|
|
319
|
&{$chainable_behavior->{chaining_behavior}}(@_); |
|
195
|
|
|
195
|
|
651
|
|
51
|
|
|
|
|
|
|
|
52
|
195
|
100
|
|
|
|
600
|
if (scalar @_ - 1 >= 1) { |
53
|
|
|
|
|
|
|
# my $old_ssfi = $class->flag($_[0], 'ssfi'); |
54
|
|
|
|
|
|
|
# |
55
|
|
|
|
|
|
|
# if (defined $old_ssfi) { # FIXME |
56
|
|
|
|
|
|
|
# $class->flag($_[0], 'ssfi', $assert); |
57
|
|
|
|
|
|
|
# } |
58
|
|
|
|
|
|
|
|
59
|
143
|
|
|
|
|
188
|
my $result = &{$chainable_behavior->{method}}(@_); |
|
143
|
|
|
|
|
485
|
|
60
|
143
|
100
|
|
|
|
75004
|
return defined $result ? $result : $_[0]; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
52
|
|
|
|
|
212
|
return $_[0]; |
64
|
22
|
|
|
|
|
75
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |