line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Flavour; |
2
|
2
|
|
|
2
|
|
34860
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
88
|
|
3
|
2
|
|
|
2
|
|
12
|
use base qw/Class::Accessor::Fast/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2018
|
|
4
|
2
|
|
|
2
|
|
17838
|
use NEXT; |
|
2
|
|
|
|
|
19056
|
|
|
2
|
|
|
|
|
76
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
2488
|
use Catalyst::Plugin::Flavour::Data; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
20
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/flavour/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# add accessors to Catalyst::Request |
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
package Catalyst::Request; |
15
|
2
|
|
|
2
|
|
164
|
use base qw/Class::Accessor::Fast/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1719
|
|
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
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This plugin allows you to handle request flavours like Blosxom. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 EXTENDED METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 prepare_path |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub prepare_path { |
43
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
44
|
0
|
|
|
|
|
|
$c->NEXT::prepare_path(@_); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# copied from Static::Simple |
47
|
0
|
|
|
|
|
|
foreach my $dir ( @{ $c->config->{static}->{dirs} } ) { |
|
0
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
my $re = ( $dir =~ /^qr\//xms ) ? eval $dir : qr/^${dir}/; |
49
|
0
|
0
|
|
|
|
|
if ($@) { |
50
|
0
|
|
|
|
|
|
$c->error( "Error compiling static dir regex '$dir': $@" ); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
0
|
|
|
|
|
if ( $c->req->path =~ $re ) { |
53
|
0
|
|
|
|
|
|
return $c; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$c->flavour( Catalyst::Plugin::Flavour::Data->new ); |
58
|
0
|
|
|
|
|
|
$c->req->real_uri( $c->req->uri->clone ); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
0
|
|
|
|
my @path = split m!/+!, $c->req->path || ''; |
61
|
0
|
0
|
0
|
|
|
|
shift @path unless @path and $path[0]; |
62
|
0
|
0
|
0
|
|
|
|
push @path, '' if ( $c->req->path || '' ) =~ m!/$!; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $config = $c->config->{flavour}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
if ( my ( $fn, $flavour ) = ( $path[-1] || '' ) =~ /(.*)\.(.*?)$/ ) { |
67
|
0
|
|
|
|
|
|
$c->flavour->fn($fn); |
68
|
0
|
|
|
|
|
|
$c->flavour->flavour($flavour); |
69
|
0
|
|
|
|
|
|
$path[-1] =~ s/\.$flavour$//; |
70
|
0
|
0
|
|
|
|
|
pop @path if $fn eq 'index'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
0
|
|
|
|
$c->flavour->fn( $path[-1] || 'index' ); |
74
|
0
|
|
0
|
|
|
|
$c->flavour->flavour( $config->{default_flavour} || 'html' ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
0
|
|
|
|
unless ( defined $config->{date_flavour} and !$config->{date_flavour} ) { |
78
|
0
|
|
|
|
|
|
for my $param (qw/year month day/) { |
79
|
0
|
0
|
|
|
|
|
last unless $path[0]; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
0
|
|
|
|
if ( $param eq 'year' && $path[0] =~ /^\d{4}$/ |
|
|
|
0
|
|
|
|
|
82
|
|
|
|
|
|
|
or $path[0] =~ /^\d?\d$/ ) |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
|
|
|
$c->flavour->$param( shift @path ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
|
last; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $path = '/' . join '/', @path; |
93
|
0
|
|
|
|
|
|
$c->req->uri->path( $path ); |
94
|
0
|
|
|
|
|
|
$c->req->path( $path ); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$c; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SEE ALSO |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<Catalyst> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
http://www.blosxom.com/ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Daisuke Murase E<lt>typester@cpan.orgE<gt> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This program is free software; you can redistribute |
112
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The full text of the license can be found in the |
115
|
|
|
|
|
|
|
LICENSE file included with this module. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |