| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MasonX::MiniMVC::Dispatcher; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4223
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw(Class::Accessor); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
967
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(controllers)); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
MasonX::MiniMVC::Dispatcher -- Dispatcher class for MasonX::MiniMVC |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.01 |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
For detailed documentation on how to use MasonX::MiniMVC, see the docs |
|
24
|
|
|
|
|
|
|
for that module. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 new(\%controllers) |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Takes a hashref of urls/controllers. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
|
33
|
0
|
|
|
0
|
1
|
|
my ($class, $controllers) = @_; |
|
34
|
0
|
|
|
|
|
|
my $self = { |
|
35
|
|
|
|
|
|
|
controllers => $controllers, |
|
36
|
|
|
|
|
|
|
}; |
|
37
|
0
|
|
|
|
|
|
bless $self, $class; |
|
38
|
0
|
|
|
|
|
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 dispatch($m) |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Dispatches to the appropriate controller. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub dispatch { |
|
48
|
0
|
|
|
0
|
1
|
|
my ($self, $m) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $dhandler_args = $m->dhandler_arg(); |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$dhandler_args =~ s/\/$//; # strip trailing slash |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my ($class, $method, @args) = $self->_find_controller($dhandler_args); |
|
55
|
0
|
0
|
|
|
|
|
if ($class) { |
|
56
|
0
|
|
|
|
|
|
eval "require $class"; |
|
57
|
0
|
0
|
|
|
|
|
if ($method) { |
|
58
|
0
|
0
|
|
|
|
|
if ($class->can($method)) { |
|
59
|
0
|
|
|
|
|
|
$class->$method($m, @args); |
|
60
|
|
|
|
|
|
|
} else { |
|
61
|
0
|
|
|
|
|
|
$class->not_found($m, $method, @args); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} else { |
|
64
|
0
|
|
|
|
|
|
$class->default($m, @args); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} else { |
|
67
|
|
|
|
|
|
|
# we want a 404 if we can't find a controller. |
|
68
|
|
|
|
|
|
|
# however, this isn't working for me under CGIHandler. |
|
69
|
0
|
|
|
|
|
|
$m->clear_and_abort(404); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _find_controller { |
|
74
|
0
|
|
|
0
|
|
|
my ($self, $desired_component, @extra_args) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# this probably means we've exhausted the arg stack |
|
77
|
0
|
0
|
|
|
|
|
return undef unless $desired_component; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
foreach my $controller (sort keys %{$self->controllers()}) { |
|
|
0
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ($controller =~ /^$desired_component/) { |
|
81
|
0
|
|
|
|
|
|
return $self->controllers->{$controller}, @extra_args; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# nothing found yet, so shift the rightmost part of the desired |
|
86
|
|
|
|
|
|
|
# component into the extra args. ie. "foo/bar/baz", "quux" becomes |
|
87
|
|
|
|
|
|
|
# "foo/bar", "baz", "quux". |
|
88
|
0
|
|
|
|
|
|
my @parts = split "/", $desired_component; |
|
89
|
0
|
|
|
|
|
|
unshift @extra_args, pop @parts; |
|
90
|
0
|
|
|
|
|
|
$desired_component = join "/", @parts; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->_find_controller($desired_component, @extra_args); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Kirrily "Skud" Robert, C<< >> |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 BUGS |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
102
|
|
|
|
|
|
|
C, or through the web interface at |
|
103
|
|
|
|
|
|
|
L. |
|
104
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
105
|
|
|
|
|
|
|
your bug as I make changes. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SUPPORT |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
perldoc MasonX::MiniMVC |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
You can also look for information at: |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 4 |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
L |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * Search CPAN |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright 2007 Kirrily "Skud" Robert, all rights reserved. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
140
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |