line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DataFlow::Role::ProcPolicy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6430
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: A role that defines how to use proc-handlers |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.121830'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
490
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use namespace::autoclean; |
13
|
|
|
|
|
|
|
use Scalar::Util 'reftype'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'handlers' => ( |
16
|
|
|
|
|
|
|
'is' => 'ro', |
17
|
|
|
|
|
|
|
'isa' => 'HashRef[CodeRef]', |
18
|
|
|
|
|
|
|
'lazy' => 1, |
19
|
|
|
|
|
|
|
'builder' => '_build_handlers', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_handlers { |
23
|
|
|
|
|
|
|
return {}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'default_handler' => ( |
27
|
|
|
|
|
|
|
'is' => 'ro', |
28
|
|
|
|
|
|
|
'isa' => 'CodeRef', |
29
|
|
|
|
|
|
|
'required' => 1, |
30
|
|
|
|
|
|
|
'builder' => '_build_default_handler', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _build_default_handler { |
34
|
|
|
|
|
|
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub apply { |
38
|
|
|
|
|
|
|
my ( $self, $p, $item ) = @_; |
39
|
|
|
|
|
|
|
my $type = _param_type($item); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $handler = |
42
|
|
|
|
|
|
|
exists $self->handlers->{$type} |
43
|
|
|
|
|
|
|
? $self->handlers->{$type} |
44
|
|
|
|
|
|
|
: $self->default_handler; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $handler->( $p, $item ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _param_type { |
50
|
|
|
|
|
|
|
my $p = shift; |
51
|
|
|
|
|
|
|
my $r = reftype($p); |
52
|
|
|
|
|
|
|
return $r ? $r : 'SVALUE'; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _make_apply_ref { |
56
|
|
|
|
|
|
|
my ( $self, $p ) = @_; |
57
|
|
|
|
|
|
|
return sub { $self->apply( $p, $_ ) }; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _run_p { |
61
|
|
|
|
|
|
|
my ( $p, $item ) = @_; |
62
|
|
|
|
|
|
|
local $_ = $item; |
63
|
|
|
|
|
|
|
return $p->(); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _nop_handle { |
67
|
|
|
|
|
|
|
my @param = @_; # ( p, item ) |
68
|
|
|
|
|
|
|
return $param[1]; # nop handle: ignores p, returns item itself |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _handle_svalue { |
72
|
|
|
|
|
|
|
my ( $p, $item ) = @_; |
73
|
|
|
|
|
|
|
return _run_p( $p, $item ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _handle_scalar_ref { |
77
|
|
|
|
|
|
|
my ( $p, $item ) = @_; |
78
|
|
|
|
|
|
|
my $r = _run_p( $p, $$item ); |
79
|
|
|
|
|
|
|
return \$r; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _handle_array_ref { |
83
|
|
|
|
|
|
|
my ( $p, $item ) = @_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#use Data::Dumper; warn 'handle_array_ref :: item = ' . Dumper($item); |
86
|
|
|
|
|
|
|
my @r = map { _run_p( $p, $_ ) } @{$item}; |
87
|
|
|
|
|
|
|
return [@r]; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _handle_hash_ref { |
91
|
|
|
|
|
|
|
my ( $p, $item ) = @_; |
92
|
|
|
|
|
|
|
my %r = map { $_ => _run_p( $p, $item->{$_} ) } keys %{$item}; |
93
|
|
|
|
|
|
|
return {%r}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _handle_code_ref { |
97
|
|
|
|
|
|
|
my ( $p, $item ) = @_; |
98
|
|
|
|
|
|
|
return sub { _run_p( $p, $item->() ) }; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding utf-8 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
DataFlow::Role::ProcPolicy - A role that defines how to use proc-handlers |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 1.121830 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 apply P ITEM |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Applies this policy to the data ITEM using function P. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 4 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L<DataFlow|DataFlow> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Alexei Znamensky <russoz@cpan.org> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Alexei Znamensky. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
143
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through the |
148
|
|
|
|
|
|
|
web interface at L<http://rt.cpan.org>. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
153
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT |
154
|
|
|
|
|
|
|
WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER |
155
|
|
|
|
|
|
|
PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, |
156
|
|
|
|
|
|
|
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
157
|
|
|
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
158
|
|
|
|
|
|
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
159
|
|
|
|
|
|
|
SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME |
160
|
|
|
|
|
|
|
THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
163
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
164
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE |
165
|
|
|
|
|
|
|
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR |
166
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
167
|
|
|
|
|
|
|
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
168
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
169
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
170
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
171
|
|
|
|
|
|
|
DAMAGES. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|