| 1 | # | ||||||||||
| 2 | # $Revision: 1.5 $ | ||||||||||
| 3 | # $Source: /home/cvs/CGI-PathParam/lib/CGI/PathParam.pm,v $ | ||||||||||
| 4 | # $Date: 2006/06/01 06:23:22 $ | ||||||||||
| 5 | # | ||||||||||
| 6 | package CGI::PathParam; | ||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | CGI::PathParam - Add the feature of parsing path_info to CGI. | ||||||||||
| 13 | |||||||||||
| 14 | =head1 VERSION | ||||||||||
| 15 | |||||||||||
| 16 | 0.04 | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | 1 | our $VERSION = '0.04'; | |||||||||
| 21 | |||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||
| 23 | |||||||||||
| 24 | use CGI; | ||||||||||
| 25 | use CGI::PathParam; | ||||||||||
| 26 | |||||||||||
| 27 | my $q = CGI->new; | ||||||||||
| 28 | |||||||||||
| 29 | $q->path_param(qw(foo bar baz)); # same as $q->path_info('/foo/bar/baz') | ||||||||||
| 30 | my @results = $q->path_param; # @results is ( 'foo', 'bar', 'baz' ). | ||||||||||
| 31 | |||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||
| 33 | |||||||||||
| 34 | This module adds the feature of parsing PATH_INFO to CGI as a plugin. | ||||||||||
| 35 | |||||||||||
| 36 | =head1 SUBROUTINES/METHODS | ||||||||||
| 37 | |||||||||||
| 38 | =head2 path_param(@) | ||||||||||
| 39 | |||||||||||
| 40 | If the arguments are specified, the values joined by / is set to path_info. | ||||||||||
| 41 | Otherwise, it returns the list of path_info split. | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub path_param { | ||||||||
|
Subroutine
path_param: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 46 | 0 | my $self = shift; | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | # When path_info(undef), only returns current path_info data. | ||||||||||
| 51 | # The behavior is same as path_info() | ||||||||||
| 52 | # However, that of path_param(undef) is *NOT* same as path_param(). | ||||||||||
| 53 | # Because path_param($param) occurs two kinds of behavior | ||||||||||
| 54 | # whether $param is undef or not. | ||||||||||
| 55 | |||||||||||
| 56 | 0 | $self->path_info( join q{/}, map { $self->escape($_) } @_ ); | |||||||||
| 57 | |||||||||||
| 58 | 0 | return $self; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | if ( !$self->path_info ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | return; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | return map { $self->unescape($_) } | |||||||||
| 66 | split m{/}msx, substr $self->path_info, 1; | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | *CGI::path_param = \&path_param; | |||||||||
| 70 | |||||||||||
| 71 | =head1 DIAGNOSTICS | ||||||||||
| 72 | |||||||||||
| 73 | =over | ||||||||||
| 74 | |||||||||||
| 75 | =item Use of uninitialized value in join or string at ... | ||||||||||
| 76 | |||||||||||
| 77 | If you pass undef to path_param then you will see this message. | ||||||||||
| 78 | |||||||||||
| 79 | =back | ||||||||||
| 80 | |||||||||||
| 81 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||
| 82 | |||||||||||
| 83 | =head1 DEPENDENCIES | ||||||||||
| 84 | |||||||||||
| 85 | L<CGI> | ||||||||||
| 86 | |||||||||||
| 87 | =head1 INCOMPATIBILITIES | ||||||||||
| 88 | |||||||||||
| 89 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 90 | |||||||||||
| 91 | The path_param() does not provide a setter feature yet. | ||||||||||
| 92 | |||||||||||
| 93 | Please report any bugs or feature requests to | ||||||||||
| 94 | C<bug-cgi-pathparam@rt.cpan.org>, or through the web interface at | ||||||||||
| 95 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-PathParam>. | ||||||||||
| 96 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 97 | your bug as I make changes. | ||||||||||
| 98 | |||||||||||
| 99 | You can find documentation for this module with the perldoc command. | ||||||||||
| 100 | |||||||||||
| 101 | perldoc CGI::PathParam | ||||||||||
| 102 | |||||||||||
| 103 | You can also look for information at: | ||||||||||
| 104 | |||||||||||
| 105 | =over 4 | ||||||||||
| 106 | |||||||||||
| 107 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 108 | |||||||||||
| 109 | L<http://annocpan.org/dist/CGI-PathParam> | ||||||||||
| 110 | |||||||||||
| 111 | =item * CPAN Ratings | ||||||||||
| 112 | |||||||||||
| 113 | L<http://cpanratings.perl.org/d/CGI-PathParam> | ||||||||||
| 114 | |||||||||||
| 115 | =item * RT: CPAN's request tracker | ||||||||||
| 116 | |||||||||||
| 117 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-PathParam> | ||||||||||
| 118 | |||||||||||
| 119 | =item * Search CPAN | ||||||||||
| 120 | |||||||||||
| 121 | L<http://search.cpan.org/dist/CGI-PathParam> | ||||||||||
| 122 | |||||||||||
| 123 | =back | ||||||||||
| 124 | |||||||||||
| 125 | =head1 AUTHOR | ||||||||||
| 126 | |||||||||||
| 127 | Hironori Yoshida, C<< <yoshida@cpan.org> >> | ||||||||||
| 128 | |||||||||||
| 129 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 130 | |||||||||||
| 131 | Copyright 2006 Hironori Yoshida, all rights reserved. | ||||||||||
| 132 | |||||||||||
| 133 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 134 | under the same terms as Perl itself. | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||
| 137 | |||||||||||
| 138 | 1 | 1; # End of CGI::PathParam | |||||||||