CGI::A...Regexp(3pm)

πŸ“¦
version 3.12 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ CGI::Application::Dispatch::Regexp πŸ’…

okay bestie, welcome to the page for CGI::Application::Dispatch::Regexp β€” it lives in the User Contributed Perl Documentation section, and it's the one that lets you dispatch requests to CGI::Application based objects using regular expressions. yes, the real ones. the powerful ones. not the fake little mini-syntax. πŸ¦‹


🌸 NAME 🌸

CGI::Application::Dispatch::Regexp β€” dispatch requests to CGI::Application based objects using regular expressions. that's the whole vibe. that's what she does. πŸ’–


✨ SYNOPSIS ✨

here's how you pull up, bestie:

use CGI::Application::Dispatch::Regexp;

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

look at that table. look at those qr|...| patterns. she's serving. πŸŽ€


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea: CGI::Application::Dispatch uses its own syntax dispatch table. cute, but limiting, ngl.

CGI::Application::Dispatch::Regexp lets you use flexible and powerful Perl regular expressions to transform a path into an argument list. that's it. that's the glow-up. no cap. πŸ”₯


🧚 DISPATCH TABLE 🧚

the dispatch table should contain a list of regular expressions with a hashref of corresponding parameters. the hash element 'names' is a list of names of regular expression groups.

the default table looks like this:

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

and here's an example of defining a custom 'page' parameter:

qr|/([^/]+)/([^/]+)/page(\d+)\.html/?| => {
    names => [qw(app rm page)],
},

see how the groups line up with the names? one group, one name, in order, left to right. the way that just works. πŸ˜­πŸ’–


Copyright Michael Peters and Mark Stosberg 2008, all rights reserved.

(polite of them to say it, honestly. respect. 🫢)


🌈 SEE ALSO 🌈

  • CGI::Application
  • CGI::Application::Dispatch

go read those too, bestie. they're the lore. iykyk. ⭐


and that's the page!! this was perl v5.34.0, dated 2022-06-09, manual page CGI::A...Regexp(3pm) β€” ty for coming to my ted talk, mwah πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from