Skip to content

Commit

Permalink
better description for split_header function
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 10, 2015
1 parent f578fba commit da8ff04
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
7 changes: 4 additions & 3 deletions lib/Mojo/URL.pm
Expand Up @@ -415,9 +415,10 @@ Normalized version of L</"scheme">.
$url = $url->query('a=1&b=2');
$url = $url->query(Mojo::Parameters->new);
Query part of this URL, pairs in an array reference will be merged with
L<Mojo::Parameters/"merge"> and pairs in a hash reference appended with
L<Mojo::Parameters/"append">, defaults to a L<Mojo::Parameters> object.
Query part of this URL, key/value pairs in an array reference will be merged
with L<Mojo::Parameters/"merge">, and key/value pairs in a hash reference
appended with L<Mojo::Parameters/"append">, defaults to a L<Mojo::Parameters>
object.
# "2"
Mojo::URL->new('http://example.com?a=1&b=2')->query->param('b');
Expand Down
24 changes: 15 additions & 9 deletions lib/Mojo/Util.pm
Expand Up @@ -48,8 +48,9 @@ my %XML = (
'\'' => '&#39;'
);

# "Sun, 06 Nov 1994 08:49:37 GMT" or "Sunday, 06-Nov-94 08:49:37 GMT"
# "Sun, 06 Nov 1994 08:49:37 GMT" and "Sunday, 06-Nov-94 08:49:37 GMT"
my $EXPIRES_RE = qr/(\w+\,\s+\d+\W+\w+\D+\d+\s+\d+:\d+:\d+\s+GMT)/;
my $VALUE_RE = qr/("(?:\\\\|\\"|[^"])*"|[^;, ]*)/;

# Encoding cache
my %CACHE;
Expand Down Expand Up @@ -387,17 +388,14 @@ sub _header {

my (@tree, @token);
while ($str =~ s/^[,;\s]*([^=;, ]+)\s*//) {
push @token, my $name = $1, undef;
push @token, $1, undef;
my $expires = $cookie && lc $1 eq 'expires';

# Special "expires" value
if ($cookie && lc $name eq 'expires' && $str =~ s/^=\s*$EXPIRES_RE//o) {
$token[-1] = $1;
}
if ($expires && $str =~ s/^=\s*$EXPIRES_RE//o) { $token[-1] = $1 }

# Normal value
elsif ($str =~ s/^=\s*("(?:\\\\|\\"|[^"])*"|[^;, ]*)\s*//) {
$token[-1] = unquote $1;
}
elsif ($str =~ s/^=\s*$VALUE_RE\s*//o) { $token[-1] = unquote $1 }

# Separator
$str =~ s/^;\s*//;
Expand Down Expand Up @@ -681,17 +679,25 @@ L<RFC 6265|http://tools.ietf.org/html/rfc6265>.
my $tree = split_header 'foo="bar baz"; test=123, yada';
Split HTTP header value.
Split HTTP header value into key/value pairs, keys without a value get
C<undef> assigned, and each comma separated part will get its own array
reference.
# "one"
split_header('one; two="three four", five=six')->[0][0];
# "two"
split_header('one; two="three four", five=six')->[0][2];
# "three four"
split_header('one; two="three four", five=six')->[0][3];
# "five"
split_header('one; two="three four", five=six')->[1][0];
# "six"
split_header('one; two="three four", five=six')->[1][1];
=head2 spurt
$bytes = spurt $bytes, '/etc/passwd';
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -659,8 +659,8 @@ Prepare a C<302> redirect response, takes the same arguments as L</"url_for">.
Render content with L<Mojolicious::Renderer/"render"> and emit hooks
L<Mojolicious/"before_render"> as well as L<Mojolicious/"after_render">, or
call L<Mojolicious::Plugin::DefaultHelpers/"reply-E<gt>not_found"> if no
response could be generated, all additional pairs get merged into the
L</"stash">.
response could be generated, all additional key/value pairs get merged into
the L</"stash">.
# Render characters
$c->render(text => 'I ♥ Mojolicious!');
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -335,7 +335,7 @@ Dump a Perl data structure with L<Mojo::Util/"dumper">.
% extends 'blue';
% extends 'blue', title => 'Blue!';
Set C<extends> stash value, all additional pairs get merged into the
Set C<extends> stash value, all additional key/value pairs get merged into the
L</"stash">.
=head2 flash
Expand Down Expand Up @@ -381,7 +381,7 @@ response headers with L<Mojolicious::Static/"is_fresh">.
% layout 'green';
% layout 'green', title => 'Green!';
Set C<layout> stash value, all additional pairs get merged into the
Set C<layout> stash value, all additional key/value pairs get merged into the
L</"stash">.
=head2 param
Expand Down Expand Up @@ -463,8 +463,8 @@ Alias for L<Mojolicious::Controller/"stash">.
% title 'Welcome!';
% title 'Welcome!', foo => 'bar';
Get or set C<title> stash value, all additional pairs get merged into the
L</"stash">.
Get or set C<title> stash value, all additional key/value pairs get merged
into the L</"stash">.
=head2 ua
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -642,7 +642,7 @@ Alias for L</"tag">.
<%= tag div => (id => 'foo') => begin %>test & 123<% end %>
HTML tag generator, the C<data> attribute may contain a hash reference with
pairs to generate attributes from.
key/value pairs to generate attributes from.
<br>
<div></div>
Expand Down

0 comments on commit da8ff04

Please sign in to comment.