line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::ASP::Dispatcher; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20656
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
6388
|
use Moose::Util::TypeConstraints; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
2067
|
use Catalyst::Action; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'Catalyst::DispatchType'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Catalyst::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
10
|
1
|
|
|
1
|
|
8
|
use Text::SimpleTable; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
818
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
CatalystX::ASP::Dispatcher - Catalyst DispatchType to match .asp requests |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package MyApp; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
after 'setup_dispatcher' => sub { |
21
|
|
|
|
|
|
|
push @{$shift->dispatcher->preload_dispatch_types}, '+CatalystX::ASP::Dispatcher'; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
__PACKAGE__->config('CatalystX::ASP' => { |
25
|
|
|
|
|
|
|
Dispatcher => { |
26
|
|
|
|
|
|
|
match_pattern => '\.asp$' |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This DispatchType will match any requests ending with .asp. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'default_action' => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => 'Catalyst::Action', |
39
|
|
|
|
|
|
|
default => sub { |
40
|
|
|
|
|
|
|
return Catalyst::Action->new( |
41
|
|
|
|
|
|
|
name => 'asp', |
42
|
|
|
|
|
|
|
code => sub { |
43
|
|
|
|
|
|
|
my ( $self, $c, @args ) = @_; |
44
|
|
|
|
|
|
|
$c->forward( $c->view( 'ASP' ), \@args ); |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
reverse => '.asp', |
47
|
|
|
|
|
|
|
namespace => '', |
48
|
|
|
|
|
|
|
class => 'CatalystX::ASP::Controller', |
49
|
|
|
|
|
|
|
attributes => [qw(ASP)], |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has '_config' => ( |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
isa => 'HashRef', |
57
|
|
|
|
|
|
|
predicate => '_has_config', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
coerce 'Regexp' |
61
|
|
|
|
|
|
|
=> from 'Str' |
62
|
|
|
|
|
|
|
=> via {qr/$_/i}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has 'match_pattern' => ( |
65
|
|
|
|
|
|
|
is => 'rw', |
66
|
|
|
|
|
|
|
isa => 'Regexp', |
67
|
|
|
|
|
|
|
coerce => 1, |
68
|
|
|
|
|
|
|
default => sub {qr/\.asp$/i}, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has '_registered_actions' => ( |
72
|
|
|
|
|
|
|
is => 'rw', |
73
|
|
|
|
|
|
|
isa => 'HashRef', |
74
|
|
|
|
|
|
|
default => sub { {} }, |
75
|
|
|
|
|
|
|
traits => [qw(Hash)], |
76
|
|
|
|
|
|
|
handles => { |
77
|
|
|
|
|
|
|
_register_action => 'set', |
78
|
|
|
|
|
|
|
}, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item $self->list($c) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Debug output for ASP dispatch points |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub list { |
92
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c ) = @_; |
93
|
0
|
|
|
|
|
0
|
my $avail_width = Catalyst::Utils::term_width() - 9; |
94
|
0
|
0
|
|
|
|
0
|
my $col1_width = ( $avail_width * .50 ) < 35 ? 35 : int( $avail_width * .50 ); |
95
|
0
|
|
|
|
|
0
|
my $col2_width = $avail_width - $col1_width; |
96
|
0
|
|
|
|
|
0
|
my $asp = Text::SimpleTable->new( |
97
|
|
|
|
|
|
|
[ $col1_width, 'Path' ], [ $col2_width, 'Private' ] |
98
|
|
|
|
|
|
|
); |
99
|
0
|
|
|
|
|
0
|
$self->_init_config( $c->config->{'CatalystX::ASP'}{Dispatcher} ); |
100
|
0
|
|
|
|
|
0
|
$asp->row( $self->match_pattern, '/asp' ); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
$c->log->debug( "Loaded ASP actions:\n" . $asp->draw . "\n" ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item $self->match($c, $path) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Checks if request path ends with .asp, and if file exists. Then creates custom |
108
|
|
|
|
|
|
|
action to forward to ASP View. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub match { |
113
|
15
|
|
|
15
|
1
|
407255
|
my ( $self, $c, $path ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
15
|
|
|
|
|
76
|
$self->_init_config( $c->config->{'CatalystX::ASP'}{Dispatcher} ); |
116
|
15
|
|
|
|
|
417
|
my $match_pattern = $self->match_pattern; |
117
|
15
|
100
|
100
|
|
|
171
|
if ( $path =~ m/$match_pattern/ && -f $c->path_to( 'root', $path ) ) { |
118
|
9
|
|
|
|
|
4814
|
$c->req->action( $path ); |
119
|
9
|
|
|
|
|
552
|
$c->req->match( $path ); |
120
|
9
|
|
|
|
|
669
|
$c->action( $self->default_action ); |
121
|
9
|
|
|
|
|
266
|
$c->namespace( $self->default_action->namespace ); |
122
|
9
|
|
|
|
|
369
|
return 1; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
6
|
|
|
|
|
939
|
return 0; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item $self->register( $c, $action ) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Registers the generated action |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub register { |
135
|
12
|
|
|
12
|
1
|
47075
|
my ( $self, $c, $action ) = @_; |
136
|
|
|
|
|
|
|
|
137
|
12
|
50
|
|
|
|
285
|
return $self->_register_action( $action->name => 1 ) if $action->attributes->{ASP}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item $self->uri_for_action($action, $captures) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Get a URI part for an action |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub uri_for_action { |
147
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $action, $captures ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
0
|
return $action->private_path; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _init_config { |
153
|
15
|
|
|
15
|
|
1324
|
my ( $self, $config ) = @_; |
154
|
15
|
100
|
|
|
|
506
|
return if $self->_has_config; |
155
|
1
|
|
50
|
|
|
31
|
$self->_config( $config || {} ); |
156
|
1
|
|
|
|
|
5
|
$self->$_( $config->{$_} ) for ( keys %$config ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SEE ALSO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=over |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item * L<CatalystX::ASP::Role> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * L<CatalystX::ASP::View> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |