Web::M...::Util(3pm)
β¨ Web::M...::Util(3pm) β¨
okay so bestie, we're looking at the manual page for Web::M...::Util, from the User Contributed Perl Documentation. pull up a chair, grab a strawberry π, this one's short but there's lore.
π NAME π
Web::Machine::Util β the General Utility module. it does bits and bobs. that's the whole vibe.
πΈ VERSION πΈ
version 0.17
π SYNOPSIS π
use Web::Machine::Util;
π¦ DESCRIPTION π¦
so this is literally just a basic little utility module that Web::Machine uses internally, like behind the curtain, doing its little jobs. there are no real user serviceable parts in here, bestie. it's giving "staff only" door. πͺβ¨
π FUNCTIONS π
"first"β this one gets imported fromList::Utiland then passed on here so it can be exported. it's a re-gift and honestly? we respect it. π"pair_key""pair_value"β these two cuties fetch the key and the value out of a pair in the Web::Machine internals. a "pair" here is simply aHASHref with exactly one key in it. one key, one vibe, no notes."inflate_headers( $request )"β this calls"inflate"on an instance ofHTTP::Headers::ActionPack. yes, inflate. like a pool floatie but for headers. π"create_header( @args )"β this calls"create"on an instance ofHTTP::Headers::ActionPack."create_date( $date_string | $time_peice )"β hand it either a$date_stringor an instance ofTime::Pieceand it will inflate it into aHTTP::Headers::ActionPack::DateHeaderobject, suitable for use in the FSM. it's basically a glow-up for dates. β¨"bind_path( $path_spec, $path )"β okay this one's the main character, let's talk. π£οΈ
give it a $path_spec (described below, keep reading bestie) and a $path, and it will either bind the path to the spec and return an array of bound values, or it will return nothing. returning nothing = no match found. no match, no service. π
also, if you call this function in scalar context and there's only one match, it'll return that one item. otherwise it returns the array as normal. which makes this idiom super easy to use:
if ( my $id = bind_path( '/:id', $request->path_info ) ) {
# handle the case with an ID here
}
else {
# handle other cases here
}
now the $path_spec follows a pretty standard convention, fr fr:
- literal path parts must match corresponding literal.
- variable path parts are prefixed by a colon
:and get captured for returning later. - if a question mark (
?) prefixes the colon, that element is considered optional. - and lastly the "splat" operator (
*) is supported, and it causes all the rest of the path segments to be returned. all of them. the whole rest of the aisle. π
here are a few examples of this:
spec path result
------------------------------------------------------------
/test/:foo/:bar /test/1/2 ( 1, 2 )
/test/:foo/:bar /test/1/ undef #failure-case
/test/* /test/1/2/3 ( 1, 2, 3 )
/user/:id/:action /user/1/edit ( 1, 'edit' )
/?:id /201 ( 201 )
/?:id / ( )
this function is kept deliberately simple, and it's expected that you'll use "my" in the array form to assign multiple variables, like this:
my ( $foo, $bar ) = bind_path( '/test/:foo/:bar', $path );
in the future we might add a "bind_path_hash" function which captures the variable names as well, but to be honest, if you feel you need that, you likely want one of the many excellent path dispatching modules available on CPAN. respectfully, go get those. π«Ά
NOTE: some care should be taken when using path specs in which the only things are either optional parameters (prefixed with"?:") or the "splat" operator ("*") as they can return empty arrays, which in certain contexts can look like match failure. π in these cases you can test the match in scalar context to verify β a match failure will be"undef", whereas a match success (in which nothing was matched) will return0(indicating an array with zero size). soundefvs0, that's the whole tea. π΅
π SUPPORT π
bugs may be submitted through <https://github.com/houseabsolute/webmachine-perl/issues>. tell them everything, bestie, they want to know. π
π AUTHORS π
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
icons. legends. the way that they wrote this. π
β COPYRIGHT AND LICENCE β
this software is copyright (c) 2016 by Infinity Interactive, Inc.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, no cap π this was Web::M...::Util(3pm), per perl v5.34.0, dated 2022-07-03. go forth and bind some paths, bestie. slay. π
β¨π¦
π¦ where this page comes from
- debian bookworm: libweb-machine-perl 0.17-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libweb-machine-perl 0.17-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms