1Flow(3)               User Contributed Perl Documentation              Flow(3)
2
3
4

NAME

6       Data::Flow - Perl extension for simple-minded recipe-controlled build
7       of data.
8

SYNOPSIS

10         use Data::Flow;
11         $recipes = { path  => { default => './MANIFEST'},
12                      contents => { prerequisites => ['path', 'x'] ,
13                                    process =>
14                                    sub {
15                                      my $data = shift;
16                                      $data->{ shift() } = `cat $data->{'path'}`
17                                        x $data->{'x'};
18                                    }
19                                  },
20                    };
21
22         $request = new Data::Flow $recipes;
23         $request->set( x => 1);
24         print $request->get('contents');
25
26         tie %request, Data::Flow, $recipes;
27         $request{x} = 1;
28         print $request{contents};
29

DESCRIPTION

31       The module Data::Flow provides its services via objects. The objects
32       may be obtained by the usual
33
34         $request = new Data::Flow $recipes;
35
36       paradigm. The argument $recipes is a hash reference, which provides the
37       rules for request processing. The objects support three methods, set(),
38       get(), aget(), and already_set(). The first one is used to provide
39       input data for processing, the second one to obtain the output. The
40       third one to obtain a reference to an array with results of repeated
41       get(), and the last one to query whether a field is already known.
42
43       The unit of requested information is a field. The method set() takes a
44       pair "field => value", the methods get() and already_set() take one
45       argument: the "field", and the method aget() takes multiple fields.
46
47       Every object is created without any fields filled, but it knows how to
48       construct fields basing on other fields or some global into. This
49       knowledge is provided in the argument $recipe of the new() function.
50       This is a reference to a hash, keyed by fields. The values of this hash
51       are hash references themselves, which describe how to acquire the field
52       which is the corresponding key of the initial hash.
53
54       The internal hashes may have the following keys:
55
56       "default"
57               describes the default value for the key, if none is provided by
58               set(). The value becomes the value of the field of the object.
59               No additional processing is performed. Example:
60
61                 default => $Config{installdir}
62
63       "prerequisites"
64               gives the fields which are needed for the construction of the
65               given field. The corresponding value is an array references.
66               The array contains the required fields.
67
68               If "defaults" did not satisfy the request for a field, but
69               "$recipe->{field}{prerequisites}" exists, the required fields
70               are build before any further processing is done. Example:
71
72                 prerequisites => [ qw(prefix arch) ]
73
74       "process"
75               contains the rule to build the field. The value is a reference
76               to a subroutine taking 2 arguments: the reference to a hash
77               with all the fields which have been set, and the name of the
78               required field. It is up to the subroutine to actually fill the
79               corresponding field of the hash, an error condition is raised
80               if it did not. Example:
81
82                 process => sub { my $data = shift;
83                                 $data->{time} = localtime(time) } }
84
85       "oo_process"
86               contains the rule to build the field. The value is a reference
87               to a subroutine taking 2 arguments: the object $request, and
88               the name of the required field. It is up to the subroutine to
89               actually fill the corresponding field of $request, an error
90               condition is raised if it did not. Example:
91
92                 oo_process => sub { my $data = shift;
93                                    $data->set( time => localtime(time) ) }
94
95       "output"
96               the corresponing value has the same meaning as for "process",
97               but the return value of the subroutine is used as the value of
98               the field. Example:
99
100                 output => sub { localtime(time) }
101
102       "oo_output"
103               the corresponing value has the same meaning as for "process",
104               but the return value of the method is used as the value of the
105               field. Example:
106
107                 output => sub { my $self = shift; $self->get('r') . localtime(time) }
108
109       "filter"
110               contains the rule to build the field basing on other fields.
111               The value is a reference to an array. The first element of the
112               array is a reference to a subroutine, the rest contains names
113               of the fields. When the subroutine is called, the arguments are
114               the values of fields of the object $request which appear in the
115               array (in the same order). The return value of the subroutine
116               is used as the value of the field. Example:
117
118                 filter => [ sub { shift + shift },
119                             'first_half', 'second_half' ]
120
121               Note that the mentioned field will be automatically marked as
122               prerequisites.
123
124       "self_filter"
125               is similar to "filter", but an extra argument, the object
126               itself, is put in front of the list of arguments.  Example:
127
128                 self_filter => [ sub { my ($self, $first_half = (shift, shift);
129                                        $first_half *= -$self->get('total')*100
130                                          if $first_half < 0;  # negative means percentage
131                                        $first_half + shift },
132                             'first_half', 'second_half' ]
133
134       "class_filter"
135               is similar to "filter", but the first argument is the name of
136               the method to call, second one is the name of the package to
137               use for the method invocation. The rest contains names of field
138               to provide as method arguments. Example:
139
140                 class_filter => [ 'new', 'FileHandle', 'filename' ]
141
142       "method_filter"
143               is similar to "class_filter", but the second argument is the
144               name of the field which is used to call the method upon.
145               Example:
146
147                 method_filter => [ 'show', 'widget_name', 'current_display' ]
148
149   Tied interface
150       The access to the same functionality is available via tied hash
151       interface.
152

AUTHOR

154       Ilya Zakharevich, cpan@ilyaz.org, with multiple additions from Terrence
155       Monroe Brannon and Radoslav Nedyalkov.
156

SEE ALSO

158       perl(1), make(1).
159
160
161
162perl v5.38.0                      2023-07-20                           Flow(3)
Impressum