line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Devel::Events::Filter::Stringify; |
4
|
1
|
|
|
1
|
|
2340
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Scalar::Util qw/reftype/; |
7
|
|
|
|
|
|
|
use overload (); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with qw/Devel::Events::Filter/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has respect_overloading => ( |
12
|
|
|
|
|
|
|
isa => "Bool", |
13
|
|
|
|
|
|
|
is => "rw", |
14
|
|
|
|
|
|
|
default => 0, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub filter_event { |
18
|
|
|
|
|
|
|
my ( $self, @event ) = @_; |
19
|
|
|
|
|
|
|
map { ref($_) ? $self->stringify($_) : $_ } @event; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub stringify { |
23
|
|
|
|
|
|
|
my ( $self, $ref ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$self->stringify_value($ref); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub stringify_value { |
29
|
|
|
|
|
|
|
my ( $self, $ref ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ( $self->respect_overloading ) { |
32
|
|
|
|
|
|
|
return "$ref"; |
33
|
|
|
|
|
|
|
} else { |
34
|
|
|
|
|
|
|
return overload::StrVal($ref); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__PACKAGE__; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=pod |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Devel::Events::Filter::Stringify - A simple event filter to prevent leaks |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Devel::Events::Filter::Stringify; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $handler = Devel::Events::Filter::Stringify->new( |
53
|
|
|
|
|
|
|
handler => $wrapped_handler, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This event filter will remove all reference data from events. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Events may contain references to the data they are reporting on. If the event |
61
|
|
|
|
|
|
|
data is not thrown away immediately this might affect the flow of the program, |
62
|
|
|
|
|
|
|
causing leaks. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This filter prevents leaks from happenning when an event logger is used by |
65
|
|
|
|
|
|
|
simply stringifying all data. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Note that objects that overload stringification will *not* have their |
68
|
|
|
|
|
|
|
stringification callbacks activated unless C<respect_overloading> is set to a |
69
|
|
|
|
|
|
|
true value. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SUBCLASSING |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
In order ot perform custom dumps of objects that are more descriptive or even |
74
|
|
|
|
|
|
|
useful for log replay, override the C<stringify> method. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=over 4 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item respect_overloading |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
See C<respect_overloading> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=back |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHODS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over 4 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item filter_event @event |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L<Devel::Events::Filter>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Will map the values in C<@event> calling C<stringify> on reference elements. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item stringify $ref |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Simply delegates to C<stringify_value> at this point. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
In the future minimal formatting may be added. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item stringify_value $ref |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This method will do either C<"$_"> or C<overload::StrVal($_)> depending on the |
105
|
|
|
|
|
|
|
value of C<respect_overloading>. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=back |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|