line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Walk::Extracted::Dispatch; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JANDREW'; |
3
|
5
|
|
|
5
|
|
446897
|
use version; our $VERSION = version->declare('v0.26.18'); |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
24
|
|
4
|
5
|
|
|
5
|
|
812
|
use Moose::Role; |
|
5
|
|
|
|
|
3061
|
|
|
5
|
|
|
|
|
28
|
|
5
|
5
|
|
|
5
|
|
18506
|
use Carp qw( confess ); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
296
|
|
6
|
|
|
|
|
|
|
if( $ENV{ Smart_Comments } ){ |
7
|
5
|
|
|
5
|
|
503
|
use Smart::Comments -ENV; |
|
5
|
|
|
|
|
19395
|
|
|
5
|
|
|
|
|
32
|
|
8
|
|
|
|
|
|
|
### Smart-Comments turned on for Data-Walk-Extracted-Dispatch ... |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#########1 private methods 3#########4#########5#########6#########7#########8#########9 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _dispatch_method{ |
14
|
3831
|
|
|
3831
|
|
4058
|
my ( $self, $dispatch_ref, $call, @arg_list ) = @_; |
15
|
|
|
|
|
|
|
### <where> - Made it to _dispatch_method |
16
|
|
|
|
|
|
|
### <where> - calling: $call |
17
|
|
|
|
|
|
|
#### <where> - for dispatch ref: $dispatch_ref |
18
|
|
|
|
|
|
|
##### <where> - the passed arguments: @arg_list |
19
|
3831
|
100
|
|
|
|
4324
|
if( exists $dispatch_ref->{$call} ){ |
|
|
50
|
|
|
|
|
|
20
|
2999
|
|
|
|
|
2043
|
my $action = $dispatch_ref->{$call}; |
21
|
|
|
|
|
|
|
##### <where> - the action is: $call |
22
|
2999
|
|
|
|
|
4445
|
return $self->$action( @arg_list ); |
23
|
|
|
|
|
|
|
}elsif( exists $dispatch_ref->{DEFAULT} ){ |
24
|
832
|
|
|
|
|
570
|
my $action = $dispatch_ref->{DEFAULT}; |
25
|
|
|
|
|
|
|
##### <where> - running the DEFAULT action ... |
26
|
832
|
|
|
|
|
1144
|
return $self->$action( @arg_list ); |
27
|
|
|
|
|
|
|
}else{ |
28
|
|
|
|
|
|
|
my $dispatch_name = |
29
|
|
|
|
|
|
|
( exists $dispatch_ref->{name} ) ? |
30
|
0
|
0
|
|
|
|
|
$dispatch_ref->{name} : undef ; |
31
|
0
|
|
|
|
|
|
my $string = "Failed to find the '$call' dispatch"; |
32
|
0
|
0
|
|
|
|
|
$string .= " in the $dispatch_name" if $dispatch_name; |
33
|
|
|
|
|
|
|
### <where> - error string: $string |
34
|
0
|
|
|
|
|
|
confess $string; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#########1 Phinish strong 3#########4#########5#########6#########7#########8#########9 |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
5
|
|
1900
|
no Moose::Role; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
30
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#########1 main pod docs 3#########4#########5#########6#########7#########8#########9 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Data::Walk::Extracted::Dispatch - Dispatch table management |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package Data::Walk::Extracted; |
56
|
|
|
|
|
|
|
use Moose; |
57
|
|
|
|
|
|
|
with 'Data::Walk::Extracted::Dispatch'; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $main_down_level_data ={ |
60
|
|
|
|
|
|
|
###### Purpose: Used to build the generic elements of the next passed ref down |
61
|
|
|
|
|
|
|
###### Recieves: the upper ref value |
62
|
|
|
|
|
|
|
###### Returns: the lower ref value or undef |
63
|
|
|
|
|
|
|
name => '- Extracted - main down level data', |
64
|
|
|
|
|
|
|
DEFAULT => sub{ undef }, |
65
|
|
|
|
|
|
|
before_method => sub{ return $_[1] }, |
66
|
|
|
|
|
|
|
after_method => sub{ return $_[1] }, |
67
|
|
|
|
|
|
|
branch_ref => \&_main_down_level_branch_ref, |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
for my $key ( keys %$upper_ref ){ |
72
|
|
|
|
|
|
|
my $return = $self->_dispatch_method( |
73
|
|
|
|
|
|
|
$main_down_level_data, $key, $upper_ref->{$key}, |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
$lower_ref->{$key} = $return if defined $return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
### this example will not run on it's own it just demonstrates usage! |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This role only serves the purpose of standardizing the handling of dispatch tables. It |
85
|
|
|
|
|
|
|
will first attempt to call the passed dispatch call. If it cannot find it then it will |
86
|
|
|
|
|
|
|
attempt a 'DEFAULT' call after which it will 'confess' to failure. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 Methods |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 _dispatch_method( $dispatch_ref, $call, @arg_list ) - internal |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=over |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
B<Definition:> To make a class extensible, the majority of the decision points |
95
|
|
|
|
|
|
|
can be managed by (hash) dispatch tables. In order to have the dispatch behavior |
96
|
|
|
|
|
|
|
common across all methods this role can be attached to the class to provided for |
97
|
|
|
|
|
|
|
common dispatching. If the hash key requested is not available then the dispatch |
98
|
|
|
|
|
|
|
method will attempt to call 'DEFAULT'. If both fail the method will 'confess'. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
B<Accepts:> This method expects to be called by $self. It first receives the |
101
|
|
|
|
|
|
|
dispatch table (hash) as a data reference. Next, the target hash key is accepted as |
102
|
|
|
|
|
|
|
$call. Finally, any arguments needed by the dispatch table are passed through in |
103
|
|
|
|
|
|
|
@arg_list. if the dispatch table has a name => key the value will be used in any |
104
|
|
|
|
|
|
|
confessed error message. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
B<Returns:> defined by the dispatch (hash) table |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=back |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 GLOBAL VARIABLES |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item B<$ENV{Smart_Comments}> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The module uses L<Smart::Comments|https://metacpan.org/module/Smart::Comments> if |
117
|
|
|
|
|
|
|
the '-ENV' option is set. The 'use' is encapsulated in an 'if' block triggered |
118
|
|
|
|
|
|
|
by an environmental variable to comfort non-believers. Setting the variable |
119
|
|
|
|
|
|
|
$ENV{Smart_Comments} will load and turn on smart comment reporting for this role. |
120
|
|
|
|
|
|
|
There are three levels of 'Smartness' available in this module '### #### #####'. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 TODO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
B<1.> Add L<Log::Shiras|https://metacpan.org/module/Log::Shiras> debugging in exchange for |
129
|
|
|
|
|
|
|
L<Smart::Comments|https://metacpan.org/module/Smart::Comments> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SUPPORT |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L<github Data-Walk-Extracted/issues|https://github.com/jandrew/Data-Walk-Extracted/issues> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 AUTHOR |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item Jed Lund |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item jandrew@cpan.org |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is free software; you can redistribute |
154
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The full text of the license can be found in the |
157
|
|
|
|
|
|
|
LICENSE file included with this module. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This software is copyrighted (c) 2013 by Jed Lund. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 Dependencies |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=over |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
L<version|https://metacpan.org/module/version> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<Carp|https://metacpan.org/module/Carp> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
L<Moose::Role|https://metacpan.org/module/Moose::Role> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
L<Smart::Comments|https://metacpan.org/module/Smart::Comments> - is used if the -ENV option is set |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L<Data::Walk::Extracted|https://metacpan.org/module/Data::Walk::Extracted> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#########1 Main POD ends 3#########4#########5#########6#########7#########8#########9 |