CatalystX-PathContext

 view release on metacpan or  search on metacpan

lib/CatalystX/PathContext.pm  view on Meta::CPAN


The string based match is always prefixed with an \A and suffixed with
(?: / | \z )

If your request path matches this match your stash would contain for example
for the Request URL look like http://localhost:3000/eng/hello the following:

  $c->stash()->{path_context}->{language}->{code} eq 'eng'

You can add multiple item like { name => ..., match => ... } to your
config - but be warned that the position of this items matters.

=head3 Last but not least you could use a subroutine reference for matching path
prefixes.

  match => sub {
      my ( $c, $request_path ) = @_;

      my ( $code )   = $request_path =~ m{\A (..) (?: / | \z ) }xms;
      my %country_of = qw(en Englang de Germany);

      if ( defined $code && exists $country_of{$code} ) {
          $c->stash()->{whateveryouwant}->{country} = $country_of{$code};
          return $code;
      }

      return;
  }

You have to take care about 2 things, which differs from the regex based
matching.

=over 1

=item 1. return a list of removed path parts or an empty list

You have to return a list of all removed prefixes or a empty list and
not undef eg. to dispatch http://localhost:3000/en/ to http://localhost:3000/
you have to return a list with the item "en". You can return more than one
item of course.

=item 2. store your context info manually

If you use subroutine references to match a path prefix the stash is
not updated for this context/prefix. -> $c->stash()->{path_context}->{country}
is not filled automatically.

=back

=head1 DEPENDENCIES

This module only works under Perl 5.10 or later.
It requires a L<Catalyst/"Catalyst"> and isa L<Moose::Role/"Moose::Role">.


=head1 INCOMPATIBILITIES

None reported.


=head1 BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to
C<bug-catalystx-pathcontext@rt.cpan.org>, or through the web interface at
L<"http://rt.cpan.org"/"http://rt.cpan.org/">.


=head1 AUTHOR

Andreas 'ac0v' Specht  C<< <ac0v@sys-network.de> >>


=head1 LICENSE AND COPYRIGHT

Copyright (c) 2010, Andreas 'ac0v' Specht C<< <ac0v@sys-network.de> >>. All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic/"perlartistic">.


=head1 DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.



( run in 1.434 second using v1.01-cache-2.11-cpan-39bf76dae61 )