The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CGI::Snapp::Dispatch::Regexp - Dispatch requests to CGI::Snapp-based objects

Synopsis

Note the call to new()!

        use CGI::Snapp::Dispatch::Regexp;

        CGI::Snapp::Dispatch::Regexp -> new -> dispatch
        (
                prefix  => 'MyApp',
                table   =>
                [
                        qr|/([^/]+)/?|                        => { names => ['app']                },
                        qr|/([^/]+)/([^/]+)/?|                => { names => [qw(app rm)]           },
                        qr|/([^/]+)/([^/]+)/page(\d+)\.html?| => { names => [qw(app rm page)]      },
                ],
        );

This would also work in a PSGI context. Note the call to new()!

        CGI::Snapp::Dispatch::Regexp -> new -> as_psgi
        (
        ...
        );

See t/psgi.regexp.t and t/regexp.t.

This usage of new(), so unlike CGI::Application::Dispatch, is dicussed in "PSGI Scripts" in CGI::Snapp::Dispatch.

Description

CGI::Snapp::Dispatch::Regexp is a sub-class of CGI::Snapp::Dispatch which overrides 2 methods:

o dispatch_args()
o _parse_path()

The point is to allow you to use regexps as rules to match the path info, whereas CGI::Snapp::Dispatch always assumes your rules are strings.

See "Description" in CGI::Snapp::Dispatch for more detail.

Distributions

This module is available as a Unix-style distro (*.tgz).

See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing distros.

Installation

Install CGI::Snapp::Dispatch as you would for any Perl module:

Run:

        cpanm CGI::Snapp::Dispatch

or run:

        sudo cpan CGI::Snapp::Dispatch

or unpack the distro, and then either:

        perl Build.PL
        ./Build
        ./Build test
        sudo ./Build install

or:

        perl Makefile.PL
        make (or dmake or nmake)
        make test
        make install

Constructor and Initialization

new() is called as my($app) = CGI::Snapp::Dispatch::Regexp -> new(k1 => v1, k2 => v2, ...).

It returns a new object of type CGI::Snapp::Dispatch::Regexp.

This module accepts exactly the same parameters as does CGI::Snapp::Dispatch.

See "Constructor and Initialization" in CGI::Snapp::Dispatch for details.

Methods

dispatch_args($args)

Returns a hashref of args to be used by "dispatch(@args)" in CGI::Snapp::Dispatch or "as_psgi(@args)" in CGI::Snapp::Dispatch.

Default output:

        {
                args_to_new => {},
                default     => '',
                prefix      => '',
                table       =>
                [
                        qr|/([^/]+)/?|         => {names => ['app']},
                        qr|/([^/]+)/([^/]+)/?| => {names => [qw/app rm/]},
                ],
        };

The differences between this structure and what's used by CGI::Snapp::Dispatch are discussed in the "FAQ".

FAQ

Is there any sample code?

Yes. See t/psgi.regexp.t and t/regexp.t.

This module works with both "dispatch(@args)" in CGI::Snapp::Dispatch and "as_psgi(@args)" in CGI::Snapp::Dispatch.

What is the structure of the dispatch table?

Basically it's the same as in "What is the structure of the dispatch table?" in CGI::Snapp::Dispatch.

The important difference is in the table key, which can be seen just above, under "dispatch_args($args)".

The pairs of elements in the table, compared to what's handled by CGI::Snapp::Dispatch are:

o A regexp instead of a string
o A hashref with a key of names and an array ref of field names

See the "Synopsis" for a more complex example.

Troubleshooting

See "Troubleshooting" in CGI::Snapp::Dispatch.

Machine-Readable Change Log

The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.

Version Numbers

Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.

Credits

See "COPYRIGHT & LICENSE" in CGI::Application::Dispatch::Regexp. This module is a fork of that code.

Support

Email the author, or log a bug on RT:

https://rt.cpan.org/Public/Dist/Display.html?Name=CGI::Snapp::Dispatch.

Author

CGI::Snapp::Dispatch was written by Ron Savage <ron@savage.net.au> in 2012.

Home page: http://savage.net.au/index.html.

Copyright

Australian copyright (c) 2012, Ron Savage.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License, a copy of which is available at:
        http://www.opensource.org/licenses/index.html