line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Flow; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
662
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1050
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
require AutoLoader; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Exporter AutoLoader); |
10
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
11
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
12
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
13
|
|
|
|
|
|
|
@EXPORT = qw( |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
$VERSION = '1.02'; # The only change 0.09 --> 1.02 is this line ;-) |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Preloaded methods go here. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
2
|
50
|
|
2
|
0
|
97
|
die "Usage: new Data::Flow \$recipes" unless @_ == 2; |
22
|
2
|
|
|
|
|
5
|
my $class = shift; |
23
|
2
|
|
|
|
|
3
|
my $recipes = shift; |
24
|
2
|
|
|
|
|
8
|
$recipes = bless [$recipes, {}], $class; |
25
|
|
|
|
|
|
|
# $recipes->set(@_); |
26
|
2
|
|
|
|
|
7
|
$recipes; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub set { |
30
|
3
|
|
|
3
|
0
|
32
|
my $self = shift; |
31
|
3
|
50
|
|
|
|
12
|
die "Odd number of data given to Data::Flow::set" if @_ % 2; |
32
|
3
|
|
|
|
|
16
|
my %data = @_; |
33
|
3
|
|
|
|
|
9
|
@{$self->[1]}{keys %data} = values %data; |
|
3
|
|
|
|
|
14
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub unset { |
37
|
0
|
|
|
0
|
0
|
0
|
my ($self, $f) = shift; |
38
|
0
|
|
|
|
|
0
|
for $f (@_) { |
39
|
0
|
|
|
|
|
0
|
delete $self->[1]{$f} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get { |
44
|
17
|
|
|
17
|
0
|
5049
|
my $self = shift; |
45
|
17
|
|
|
|
|
42
|
my $request = shift; |
46
|
17
|
|
|
|
|
42
|
$self->request($request); |
47
|
17
|
|
|
|
|
229
|
$self->[1]->{$request}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub aget { |
51
|
1
|
|
|
1
|
0
|
9
|
my $self = shift; |
52
|
1
|
|
|
|
|
3
|
[map { $self->request($_); $self->[1]->{$_} } @_] |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub already_set { |
56
|
2
|
|
|
2
|
0
|
38
|
my $self = shift; |
57
|
2
|
|
|
|
|
4
|
my $request = shift; |
58
|
2
|
|
|
|
|
17
|
exists $self->[1]->{$request}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub request { |
62
|
37
|
|
|
37
|
0
|
43
|
my $self = shift; |
63
|
37
|
|
|
|
|
46
|
my ($recipes, $data) = @$self; |
64
|
37
|
|
|
|
|
44
|
my ($recipe, $request); |
65
|
37
|
|
|
|
|
55
|
for $request (@_) { |
66
|
|
|
|
|
|
|
# Bail out if present |
67
|
39
|
100
|
|
|
|
129
|
next if exists $data->{$request}; |
68
|
20
|
|
|
|
|
41
|
$recipe = $recipes->{$request}; |
69
|
|
|
|
|
|
|
# Get prerequisites |
70
|
20
|
100
|
|
|
|
47
|
$self->request(@{$recipe->{prerequisites}}) |
|
9
|
|
|
|
|
49
|
|
71
|
|
|
|
|
|
|
if exists $recipe->{prerequisites}; |
72
|
|
|
|
|
|
|
# Check for default value |
73
|
20
|
100
|
|
|
|
305
|
if (exists $recipe->{default}) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
74
|
2
|
|
|
|
|
12
|
$data->{$request} = $recipe->{default}; |
75
|
2
|
|
|
|
|
6
|
next; |
76
|
|
|
|
|
|
|
} elsif (exists $recipe->{process}) { # Let it do the work itself. |
77
|
2
|
|
|
|
|
3
|
&{$recipe->{process}}($data, $request); |
|
2
|
|
|
|
|
11
|
|
78
|
2
|
50
|
|
|
|
221
|
die "The recipe for processing the request `$request' did not acquire it" |
79
|
|
|
|
|
|
|
unless exists $data->{$request}; |
80
|
|
|
|
|
|
|
} elsif (exists $recipe->{oo_process}) { # Let it do the work itself. |
81
|
1
|
|
|
|
|
2
|
&{$recipe->{oo_process}}($self, $request); |
|
1
|
|
|
|
|
5
|
|
82
|
1
|
50
|
|
|
|
6
|
die "The recipe for OO-processing the request `$request' did not acquire it" |
83
|
|
|
|
|
|
|
unless exists $data->{$request}; |
84
|
|
|
|
|
|
|
} elsif (exists $recipe->{output}) { # Keep return value. |
85
|
6
|
|
|
|
|
9
|
$data->{$request} = &{$recipe->{output}}($data, $request); |
|
6
|
|
|
|
|
23
|
|
86
|
|
|
|
|
|
|
} elsif (exists $recipe->{oo_output}) { # Keep return value. |
87
|
0
|
|
|
|
|
0
|
$data->{$request} = &{$recipe->{oo_output}}($self, $request); |
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
} elsif (exists $recipe->{filter}) { # Input comes from $data |
89
|
2
|
|
|
|
|
2
|
my @arr = @{ $recipe->{filter} }; |
|
2
|
|
|
|
|
12
|
|
90
|
2
|
|
|
|
|
3
|
my $sub = shift @arr; |
91
|
2
|
|
|
|
|
8
|
foreach (@arr) { $self->request($_) } |
|
2
|
|
|
|
|
28
|
|
92
|
2
|
|
|
|
|
14
|
@arr = map $data->{$_}, @arr; |
93
|
2
|
|
|
|
|
8
|
$data->{$request} = &$sub( @arr ); |
94
|
|
|
|
|
|
|
} elsif (exists $recipe->{self_filter}) { # Input comes from $data |
95
|
1
|
|
|
|
|
2
|
my @arr = @{ $recipe->{self_filter} }; |
|
1
|
|
|
|
|
4
|
|
96
|
1
|
|
|
|
|
3
|
my $sub = shift @arr; |
97
|
1
|
|
|
|
|
3
|
foreach (@arr) { $self->request($_) } |
|
1
|
|
|
|
|
4
|
|
98
|
1
|
|
|
|
|
4
|
@arr = map $data->{$_}, @arr; |
99
|
1
|
|
|
|
|
5
|
$data->{$request} = &$sub( $self, @arr ); |
100
|
|
|
|
|
|
|
} elsif (exists $recipe->{method_filter}) { # Input comes from $data |
101
|
2
|
|
|
|
|
5
|
my @arr = @{ $recipe->{method_filter} }; |
|
2
|
|
|
|
|
6
|
|
102
|
2
|
|
|
|
|
5
|
my $method = shift @arr; |
103
|
2
|
|
|
|
|
3
|
foreach (@arr) { $self->request($_) } |
|
4
|
|
|
|
|
26
|
|
104
|
2
|
|
|
|
|
11
|
@arr = map $data->{$_}, @arr; |
105
|
2
|
|
|
|
|
4
|
my $obj = shift @arr; |
106
|
2
|
|
|
|
|
32
|
$data->{$request} = $obj->$method( @arr ); |
107
|
|
|
|
|
|
|
} elsif (exists $recipe->{class_filter}) { # Input comes from $data |
108
|
4
|
|
|
|
|
5
|
my @arr = @{ $recipe->{class_filter} }; |
|
4
|
|
|
|
|
13
|
|
109
|
4
|
|
|
|
|
9
|
my $method = shift @arr; |
110
|
4
|
|
|
|
|
4
|
my $class = shift @arr; |
111
|
4
|
|
|
|
|
10
|
foreach (@arr) { $self->request($_) } |
|
2
|
|
|
|
|
6
|
|
112
|
4
|
|
|
|
|
9
|
@arr = map $data->{$_}, @arr; |
113
|
4
|
|
|
|
|
28
|
$data->{$request} = $class->$method( @arr ); |
114
|
|
|
|
|
|
|
} else { |
115
|
0
|
0
|
|
|
|
|
die "Do not know how to satisfy the request `$request'" |
116
|
|
|
|
|
|
|
unless exists $data->{$request}; # 'prerequisites' could set it |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
*TIEHASH = \&new; |
122
|
|
|
|
|
|
|
*STORE = \&set; |
123
|
|
|
|
|
|
|
*FETCH = \&get; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
__END__ |