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


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.


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.


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

See for help on unpacking and installing distros.


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


        cpanm CGI::Snapp::Dispatch

or run:

        sudo cpan CGI::Snapp::Dispatch

or unpack the distro, and then either:

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


        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.



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".


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.


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.


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


Email the author, or log a bug on RT:


CGI::Snapp::Dispatch was written by Ron Savage <> in 2012.

Home page:


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: