File Coverage

blib/lib/Catalyst/DispatchType/LocalRegex.pm
Criterion Covered Total %
statement 12 12 100.0
branch 3 4 75.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 18 19 94.7


line stmt bran cond sub pod time code
1             package Catalyst::DispatchType::LocalRegex;
2              
3 3     3   2859 use Moose;
  3         5  
  3         15  
4             extends 'Catalyst::DispatchType::Regex';
5             has '+_attr' => ( default => 'LocalRegex' );
6              
7             =head1 NAME
8              
9             Catalyst::DispatchType::LocalRegex - LocalRegex DispatchType
10              
11             =head1 SYNOPSIS
12              
13             See L<Catalyst::DispatchType>.
14              
15             =head1 DESCRIPTION
16              
17             B<Status: Deprecated.> Regex dispatch types have been deprecated and removed
18             from Catalyst core. It is recommend that you use Chained methods or other
19             techniques instead. As part of the refactoring, the dispatch priority of
20             Regex vs Regexp vs LocalRegex vs LocalRegexp may have changed. Priority is now
21             influenced by when the dispatch type is first seen in your application.
22              
23             When loaded, a warning about the deprecation will be printed to STDERR. To
24             suppress the warning set the CATALYST_NOWARN_DEPRECATE environment variable to
25             a true value.
26              
27             Dispatch type managing path-matching behaviour using regexes. For
28             more information on dispatch types, see:
29              
30             =over 4
31              
32             =item * L<Catalyst::Manual::Intro> for how they affect application authors
33              
34             =item * L<Catalyst::DispatchType> for implementation information.
35              
36             =back
37              
38             =cut
39              
40             around '_get_attributes' => sub {
41             my ( $orig, $self, $c, $action ) = splice( @_, 0, 4 );
42             my @attributes = $self->$orig( $c, $action, @_ );
43             return map { $self->_parse_LocalRegex_attr( $c, $action, $_ ) }
44             @attributes;
45             };
46              
47             sub _parse_LocalRegex_attr {
48 18     18   26 my ( $self, $c, $action, $value ) = @_;
49 18 100       50 unless ( $value =~ s/^\^// ) { $value = "(?:.*?)$value"; }
  12         16  
50              
51 18         426 my $prefix = $action->namespace();
52 18 50       107 $prefix .= '/' if length( $prefix );
53              
54 18         79 return "^${prefix}${value}";
55             }
56              
57 3     3   14067 no Moose;
  3         7  
  3         10  
58              
59             =head1 AUTHORS
60              
61             Catalyst Contributors, see Catalyst.pm
62              
63             =head1 COPYRIGHT
64              
65             This library is free software. You can redistribute it and/or modify it under
66             the same terms as Perl itself.
67              
68             =cut
69              
70             __PACKAGE__->meta->make_immutable;
71              
72             1;