1Web::Machine::Util(3) User Contributed Perl DocumentationWeb::Machine::Util(3)
2
3
4

NAME

6       Web::Machine::Util - General Utility module
7

VERSION

9       version 0.17
10

SYNOPSIS

12         use Web::Machine::Util;
13

DESCRIPTION

15       This is just a basic utility module used internally by Web::Machine.
16       There are no real user serviceable parts in here.
17

FUNCTIONS

19       "first"
20           This is imported from List::Util and passed on here for export.
21
22       "pair_key"
23       "pair_value"
24           These two functions are used for fetching the key and value out of
25           a pair in the Web::Machine internals.  We represent a pair simply
26           as a HASH ref with one key.
27
28       "inflate_headers( $request )"
29           This will call "inflate" on an instance of
30           HTTP::Headers::ActionPack.
31
32       "create_header( @args )"
33           This will call "create" on an instance of
34           HTTP::Headers::ActionPack.
35
36       "create_date( $date_string | $time_peice )"
37           Given either a $date_string or an instance of Time::Piece, this
38           will inflate it into a HTTP::Headers::ActionPack::DateHeader
39           object, suitable for use in the FSM.
40
41       "bind_path( $path_spec, $path )"
42           Given a $path_spec (described below) and a $path, this will either
43           bind the path to the spec and return and array of bound values, or
44           it will return nothing. Returning nothing indicates that no match
45           was found. Additionally, if this function is called in scalar
46           context, and there is only one match, it will return that item.
47           Otherwise it will return the array as normal. This all makes it
48           easy to use the following idiom:
49
50             if ( my $id = bind_path( '/:id', $request->path_info ) ) {
51                 # handle the case with an ID here
52             }
53             else {
54                 # handle other cases here
55             }
56
57           The $path_spec follows a pretty standard convention. Literal path
58           parts must match corresponding literal. Variable path parts are
59           prefixed by a colon and are captured for returning later, if a
60           question mark (?) prefixes the colon, that element will be
61           considered optional. And lastly the "splat" operator ("*") is
62           supported and causes all the rest of the path segments to be
63           returned. Below are a few examples of this:
64
65             spec                  path             result
66             ------------------------------------------------------------
67             /test/:foo/:bar       /test/1/2        ( 1, 2 )
68             /test/:foo/:bar       /test/1/         undef #failure-case
69             /test/*               /test/1/2/3      ( 1, 2, 3 )
70             /user/:id/:action     /user/1/edit     ( 1, 'edit' )
71             /?:id                 /201             ( 201 )
72             /?:id                 /                ( )
73
74           This function is kept deliberately simple and it is expected that
75           the user will use "my" in the array form to assign multiple
76           variables, like this:
77
78             my ( $foo, $bar ) = bind_path( '/test/:foo/:bar', $path );
79
80           In the future we might add a "bind_path_hash" function which
81           captures the variable names as well, but to be honest, if you feel
82           you need that, you likely want one of the many excellent path
83           dispatching modules available on CPAN.
84
85           NOTE: Some care should be taken when using path specs in which the
86           only things are either optional parameters (prefixed with "?:") or
87           the "splat" operator ("*") as they can return empty arrays, which
88           in certain contexts can look like match failure. In these cases you
89           can test the match in scalar context to verify, a match failure
90           will be "undef" whereas a match success (in which nothing was
91           matched) will return 0 (indicating an array with zero size).
92

SUPPORT

94       bugs may be submitted through
95       <https://github.com/houseabsolute/webmachine-perl/issues>.
96

AUTHORS

98       •   Stevan Little <stevan@cpan.org>
99
100       •   Dave Rolsky <autarch@urth.org>
101
103       This software is copyright (c) 2016 by Infinity Interactive, Inc.
104
105       This is free software; you can redistribute it and/or modify it under
106       the same terms as the Perl 5 programming language system itself.
107
108
109
110perl v5.34.0                      2022-01-21             Web::Machine::Util(3)
Impressum