line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Dispatch; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Dispatch.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
1
|
|
|
1
|
|
478
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
9
|
1
|
|
|
1
|
|
6
|
use Carp qw/ croak /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
168
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION= '3.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
0
|
|
|
0
|
|
|
my($class)= @_; |
15
|
0
|
|
|
|
|
|
my($project)= $class=~m{^([^\:]+)}; |
16
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; ## no critic |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
17
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
487
|
|
18
|
0
|
|
|
|
|
|
*{"${class}::code"}= sub { |
19
|
0
|
0
|
|
0
|
|
|
shift if ref($_[0]); |
20
|
0
|
|
0
|
|
|
|
my $pkg= shift || croak q{ I want include package name. }; |
21
|
0
|
|
|
|
|
|
$pkg= "${project}::$pkg"; |
22
|
0
|
|
0
|
|
|
|
my $method= shift || croak q{ I want method name. }; |
23
|
0
|
0
|
|
|
|
|
$pkg->require or die $@; |
24
|
0
|
0
|
|
|
|
|
$pkg->can($method) || croak qq{ '$method' method is not found. }; |
25
|
0
|
|
|
|
|
|
}; |
26
|
0
|
|
|
|
|
|
*{"${class}::mode_param"}= sub { |
27
|
0
|
0
|
|
0
|
|
|
my $proto= shift; return 0 if ref($proto); |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
0
|
|
|
|
my $pname= shift || croak(q{ I want param name. }); |
29
|
0
|
|
|
|
|
|
my $name_uc= uc $project; |
30
|
0
|
|
|
|
|
|
*{"${proto}::_get_mode"}= sub { |
31
|
0
|
0
|
0
|
|
|
|
$ENV{"${name_uc}_REQUEST_PARTS"} |
32
|
|
|
|
|
|
|
|| $_[0]->request->param($pname) |
33
|
|
|
|
|
|
|
|| return (undef); |
34
|
0
|
|
|
|
|
|
}; |
35
|
0
|
|
|
|
|
|
}; |
36
|
0
|
|
|
|
|
|
$class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub dispatch_map { |
40
|
0
|
|
|
0
|
1
|
|
my $e= shift; |
41
|
0
|
0
|
|
|
|
|
return $e->_dispatch_map unless @_; |
42
|
0
|
0
|
|
|
|
|
my $hash= $_[0] ? ($_[1] ? {@_}: $_[0]): return 0; |
|
|
0
|
|
|
|
|
|
43
|
0
|
|
0
|
|
|
|
$e->_dispatch_map( $e->_dispatch_map_check($hash, (ref($e) || $e)) ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
*run_modes= \&dispatch_map; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
0
|
|
|
sub _dispatch_map_check { $_[1] || {} } |
48
|
0
|
|
|
0
|
|
|
sub _get_mode { 0 } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package Egg::Dispatch::handler; |
51
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
52
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
53
|
1
|
|
|
1
|
|
6
|
use base qw/ Egg::Base /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
403
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ mode label default_mode default_name /); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
|
|
sub new { shift->SUPER::new(@_)->_initialize } |
58
|
0
|
|
|
0
|
|
|
sub action { shift->e->action(@_) } |
59
|
0
|
|
|
0
|
|
|
sub stash { $_[0]->e->stash } |
60
|
0
|
|
|
0
|
|
|
sub config { $_[0]->e->config } |
61
|
0
|
|
|
0
|
|
|
sub page_title { shift->e->page_title(@_) } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub target_action { |
64
|
0
|
|
|
0
|
|
|
my($self)= @_; |
65
|
0
|
|
0
|
|
|
|
my $action= $self->action || return ""; |
66
|
0
|
0
|
|
|
|
|
@$action ? '/'. join('/', @$action): ""; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
sub _initialize { |
69
|
0
|
|
|
0
|
|
|
my($self)= @_; |
70
|
0
|
|
|
|
|
|
my $cf= $self->e->config; |
71
|
0
|
|
|
|
|
|
$self->{label} = []; |
72
|
0
|
|
|
|
|
|
$self->{action}= []; |
73
|
0
|
|
|
|
|
|
$self->{page_title}= ""; |
74
|
0
|
|
0
|
|
|
|
$self->{default_name}= $cf->{template_default_name} || 'index'; |
75
|
0
|
|
0
|
|
|
|
$self->{default_mode}= $cf->{deispath_default_name} || '_default'; |
76
|
0
|
|
|
|
|
|
$self; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
0
|
|
|
sub _example_code { 'none.' } |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Egg::Dispatch - Base class for dispatch. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 DESCRIPTION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
It is a base class for dispatch. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
To do the function as Dispatch, necessary minimum method is offered. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L<Egg::Dispatch::Standard>, L<Egg::Dispatch::Fast>, |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 dispatch_map ([DISPATCH_HASH]) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The setting of dispatch is returned. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
When DISPATCH_HASH is given, it is set as dispatch. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Egg->dispatch_map ( |
105
|
|
|
|
|
|
|
_default => sub {}, |
106
|
|
|
|
|
|
|
hoge => sub { ... }, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 4 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * Alias = run_modes |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 HANDLER METHODS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<Egg::Base> has been succeeded to. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 new |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Constructor. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 action |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$e-E<gt>action is returned. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 stash |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$e-E<gt>stash is returned. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 config |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$e-E<gt>config is returned. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 page_title |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$e-E<gt>page_title is returned. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 target_action |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The URI passing to decided action is assembled and it returns it. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 mode |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Accessor to treat mode. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 label |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Accessor to treat label. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 default_mode |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The mode of default is returned. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
It is revokable in 'deispath_default_name' of the configuration. |
156
|
|
|
|
|
|
|
Default is '_default'. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 default_name |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The template name of default is returned. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
It is revokable in 'template_default_name' of the configuration. |
163
|
|
|
|
|
|
|
Default is 'index'. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<Egg::Release>, |
168
|
|
|
|
|
|
|
L<Egg::Base>, |
169
|
|
|
|
|
|
|
L<Egg::Dispatch::Standard>, |
170
|
|
|
|
|
|
|
L<Egg::Dispatch::Fast>, |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
181
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
182
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|