line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Flavour; |
2
|
1
|
|
|
1
|
|
15533
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
4
|
use base qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
592
|
|
4
|
1
|
|
|
1
|
|
4267
|
use NEXT; |
|
1
|
|
|
|
|
3779
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
522
|
use Catalyst::Plugin::Flavour::Data; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.029_01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/flavour/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# add accessors to Catalyst::Request |
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
package Catalyst::Request; |
15
|
1
|
|
|
1
|
|
73
|
use base qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
508
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/real_uri/); |
18
|
|
|
|
|
|
|
*rpath = \&real_path; |
19
|
|
|
|
|
|
|
*ruri = \&real_uri; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
|
|
sub real_path { shift->real_uri->path }; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Catalyst::Plugin::Flavour - Catalyst plugin for request flavours. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Catalyst qw/Flavour/; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__PACKAGE__->config( |
33
|
|
|
|
|
|
|
flavour => { |
34
|
|
|
|
|
|
|
flavours => [qw/html rss json/], |
35
|
|
|
|
|
|
|
default_flavour => 'html', |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This plugin allows you to handle request flavours like Blosxom. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
When top level path token in request match your flavour, that is stored in $c->flavour and deleted $c->path while $c->prepare_path. |
44
|
|
|
|
|
|
|
So you can handle several flavours same controllers. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 EXTENDED METHODS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 prepare_path |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub prepare_path { |
53
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
54
|
0
|
|
|
|
|
|
$c->NEXT::prepare_path(@_); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$c->flavour( Catalyst::Plugin::Flavour::Data->new ); |
57
|
0
|
|
|
|
|
|
$c->req->real_uri( $c->req->uri->clone ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my @path = split m!/+!, $c->req->path; |
60
|
0
|
0
|
0
|
|
|
|
shift @path unless @path and $path[0]; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $config = $c->config->{flavour}; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
0
|
|
|
|
if ($config->{flavours} or $config->{flavours_except}) { |
|
|
0
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $flavours = { |
66
|
0
|
|
|
|
|
|
map { $_ => 1 } |
67
|
0
|
0
|
0
|
|
|
|
@{ $config->{flavours} || $config->{flavours_except} || [] } |
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $flavour = $path[0]; |
71
|
0
|
0
|
0
|
|
|
|
if ($config->{flavours} && $flavours->{$flavour} |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
72
|
|
|
|
|
|
|
or $config->{flavours_except} && !$flavours->{$flavour}) { |
73
|
0
|
|
|
|
|
|
shift @path; |
74
|
0
|
|
|
|
|
|
$c->flavour->flavour($flavour); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
0
|
|
|
|
$c->flavour->flavour( $c->config->{flavour}->{default_flavour} || 'html' ) |
77
|
|
|
|
|
|
|
unless $c->flavour; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ( my ( $fn, $flavour ) = $path[-1] =~ /(.*)\.(.*?)$/ ) { |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$c->flavour->flavour($flavour); |
83
|
0
|
0
|
|
|
|
|
if ( $fn eq 'index' ) { |
84
|
0
|
|
|
|
|
|
pop @path; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
|
$path[-1] =~ s/\.$flavour$//; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
0
|
|
|
|
unless ( defined $config->{date_flavour} and !$config->{date_flavour} ) { |
92
|
0
|
|
|
|
|
|
for my $param (qw/year month day/) { |
93
|
0
|
0
|
|
|
|
|
last unless $path[0]; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
0
|
|
|
|
if ( $param eq 'year' && $path[0] =~ /^\d{4}$/ |
|
|
|
0
|
|
|
|
|
96
|
|
|
|
|
|
|
or $path[0] =~ /^\d?\d$/ ) |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
|
|
|
$c->flavour->$param( shift @path ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
0
|
|
|
|
|
|
last; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $path = '/' . join '/', @path; |
107
|
0
|
|
|
|
|
|
$c->req->uri->path( $path ); |
108
|
0
|
|
|
|
|
|
$c->req->path( $path ); |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$c; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SEE ALSO |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L<Catalyst> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
http://www.blosxom.com/ |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Daisuke Murase E<lt>typester@cpan.orgE<gt> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This program is free software; you can redistribute |
126
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The full text of the license can be found in the |
129
|
|
|
|
|
|
|
LICENSE file included with this module. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |