Flavour.pm

filter: Statementstmt 100% 6 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 8 / 8 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary Flavour/Data.pm »
1 package Catalyst::Plugin::Flavour;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 use NEXT;
5  
6 use Catalyst::Plugin::Flavour::Data;
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 use base qw/Class::Accessor::Fast/;
16  
17 __PACKAGE__->mk_accessors(qw/real_uri/);
18 *rpath = \&real_path;
19 *ruri = \&real_uri;
20  
21 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 my $c = shift;
44 $c->NEXT::prepare_path(@_);
45  
46 # copied from Static::Simple
47 foreach my $dir ( @{ $c->config->{static}->{dirs} } ) {
48 my $re = ( $dir =~ /^qr\//xms ) ? eval $dir : qr/^${dir}/;
49 if ($@) {
50 $c->error( "Error compiling static dir regex '$dir': $@" );
51 }
52 if ( $c->req->path =~ $re ) {
53 return $c;
54 }
55 }
56  
57 $c->flavour( Catalyst::Plugin::Flavour::Data->new );
58 $c->req->real_uri( $c->req->uri->clone );
59  
60 my @path = split m!/+!, $c->req->path || '';
61 shift @path unless @path and $path[0];
62 push @path, '' if ( $c->req->path || '' ) =~ m!/$!;
63  
64 my $config = $c->config->{flavour};
65  
66 if ( my ( $fn, $flavour ) = ( $path[-1] || '' ) =~ /(.*)\.(.*?)$/ ) {
67 $c->flavour->fn($fn);
68 $c->flavour->flavour($flavour);
69 $path[-1] =~ s/\.$flavour$//;
70 pop @path if $fn eq 'index';
71 }
72 else {
73 $c->flavour->fn( $path[-1] || 'index' );
74 $c->flavour->flavour( $config->{default_flavour} || 'html' );
75 }
76  
77 unless ( defined $config->{date_flavour} and !$config->{date_flavour} ) {
78 for my $param (qw/year month day/) {
79 last unless $path[0];
80  
81 if ( $param eq 'year' && $path[0] =~ /^\d{4}$/
82 or $path[0] =~ /^\d?\d$/ )
83 {
84 $c->flavour->$param( shift @path );
85 }
86 else {
87 last;
88 }
89 }
90 }
91  
92 my $path = '/' . join '/', @path;
93 $c->req->uri->path( $path );
94 $c->req->path( $path );
95  
96 $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;
↑ Summary Flavour/Data.pm »