line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# DESCRIPTION: |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# AUTHOR: Aliaksandr P. Zahatski, |
6
|
|
|
|
|
|
|
#=============================================================================== |
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Flow::Code - process flow by user defined code |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $f1 = Flow::create_flow( |
14
|
|
|
|
|
|
|
Splice => 200, |
15
|
|
|
|
|
|
|
Join => { |
16
|
|
|
|
|
|
|
Data => Flow::create_flow( |
17
|
|
|
|
|
|
|
sub { |
18
|
|
|
|
|
|
|
return [ grep { $_ > 10 } @_ ]; |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
Splice => 10 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
), |
23
|
|
|
|
|
|
|
Min => Flow::create_flow( |
24
|
|
|
|
|
|
|
sub { |
25
|
|
|
|
|
|
|
return [ grep { $_ == 1 } @_ ]; |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
Splice => 40, |
28
|
|
|
|
|
|
|
) |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
ToXML => \$s, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
$f1->run( 1, 3, 11 ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
package Flow::Code; |
37
|
8
|
|
|
8
|
|
39
|
use strict; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
308
|
|
38
|
8
|
|
|
8
|
|
36
|
use warnings; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
226
|
|
39
|
8
|
|
|
8
|
|
33
|
use base 'Flow'; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
1098
|
|
40
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
new Flow::Code:: { flow=>sub{ shift; [] }[, begin=>sub{ shift ..}, end .., cnt_flow=>... }; |
45
|
|
|
|
|
|
|
new Flow::Code:: sub{ \@_ } #default handle flow |
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
foreach my $method ( "begin", "flow", "ctl_flow", "end" ) { |
49
|
|
|
|
|
|
|
my $s_method = "SUPER::" . $method; |
50
|
8
|
|
|
8
|
|
43
|
no strict 'refs'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
1807
|
|
51
|
|
|
|
|
|
|
*{ __PACKAGE__ . "::$method" } = sub { |
52
|
0
|
|
|
0
|
|
|
my $self = shift; |
53
|
0
|
0
|
|
|
|
|
if ( my $code = $self->{ "_" . $method } ) { |
|
|
0
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return &$code(@_); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ( my $code_s = $self->{$method} ) { |
57
|
0
|
|
|
|
|
|
return &$code_s( $self, @_ ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
|
return $self->$s_method(@_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
66
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
67
|
0
|
0
|
0
|
|
|
|
if ( $#_ == 0 and ref( $_[0] ) eq 'CODE' ) { |
68
|
0
|
|
|
|
|
|
unshift @_, '_flow'; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#clean up hnot valided handlers |
73
|
0
|
|
|
|
|
|
foreach my $method (qw/ begin flow ctl_flow end /) { |
74
|
0
|
|
0
|
|
|
|
my $code = $self->{$method} || next; |
75
|
0
|
0
|
|
|
|
|
delete $self->{$method} unless ref($code) eq 'CODE'; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |