Skip to content

Commit

Permalink
changed semantics of almost all functions in Mojo::Util
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 1, 2011
1 parent 1cfb69a commit e3a6590
Show file tree
Hide file tree
Showing 32 changed files with 218 additions and 282 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@
This file documents the revision history for Perl extension Mojolicious.

2.20 2011-10-31 00:00:00
2.20 2011-11-01 00:00:00
- Changed semantics of almost all functions in Mojo::Util.
- Documentation improvements.

2.19 2011-10-31 00:00:00
Expand Down
36 changes: 18 additions & 18 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -35,7 +35,7 @@ sub b64_encode {

sub camelize {
my $self = shift;
Mojo::Util::camelize $$self;
$$self = Mojo::Util::camelize $$self;
return $self;
}

Expand All @@ -46,7 +46,7 @@ sub clone {

sub decamelize {
my $self = shift;
Mojo::Util::decamelize $$self;
$$self = Mojo::Util::decamelize $$self;
return $self;
}

Expand All @@ -57,13 +57,13 @@ sub decamelize {
# Number 3: 'It was like that when I got here.'"
sub decode {
my $self = shift;
Mojo::Util::decode shift || 'UTF-8', $$self;
$$self = Mojo::Util::decode shift || 'UTF-8', $$self;
return $self;
}

sub encode {
my $self = shift;
Mojo::Util::encode shift || 'UTF-8', $$self;
$$self = Mojo::Util::encode shift || 'UTF-8', $$self;
return $self;
}

Expand All @@ -81,13 +81,13 @@ sub hmac_sha1_sum {

sub html_escape {
my $self = shift;
Mojo::Util::html_escape $$self;
$$self = Mojo::Util::html_escape $$self;
return $self;
}

sub html_unescape {
my $self = shift;
Mojo::Util::html_unescape $$self;
$$self = Mojo::Util::html_unescape $$self;
return $self;
}

Expand All @@ -105,13 +105,13 @@ sub md5_sum {

sub punycode_decode {
my $self = shift;
Mojo::Util::punycode_decode $$self;
$$self = Mojo::Util::punycode_decode $$self;
return $self;
}

sub punycode_encode {
my $self = shift;
Mojo::Util::punycode_encode $$self;
$$self = Mojo::Util::punycode_encode $$self;
return $self;
}

Expand All @@ -120,19 +120,19 @@ sub punycode_encode {
# nutrients they have that might be extracted for our personal use."
sub qp_decode {
my $self = shift;
Mojo::Util::qp_decode $$self;
$$self = Mojo::Util::qp_decode $$self;
return $self;
}

sub qp_encode {
my $self = shift;
Mojo::Util::qp_encode $$self;
$$self = Mojo::Util::qp_encode $$self;
return $self;
}

sub quote {
my $self = shift;
Mojo::Util::quote $$self;
$$self = Mojo::Util::quote $$self;
return $self;
}

Expand Down Expand Up @@ -170,31 +170,31 @@ sub to_string { ${shift()} }

sub trim {
my $self = shift;
Mojo::Util::trim $$self, @_;
$$self = Mojo::Util::trim $$self;
return $self;
}

sub unquote {
my $self = shift;
Mojo::Util::unquote $$self, @_;
$$self = Mojo::Util::unquote $$self;
return $self;
}

sub url_escape {
my $self = shift;
Mojo::Util::url_escape $$self, @_;
$$self = Mojo::Util::url_escape $$self, @_;
return $self;
}

sub url_unescape {
my $self = shift;
Mojo::Util::url_unescape $$self;
$$self = Mojo::Util::url_unescape $$self;
return $self;
}

sub xml_escape {
my $self = shift;
Mojo::Util::xml_escape $$self;
$$self = Mojo::Util::xml_escape $$self;
return $self;
}

Expand Down Expand Up @@ -332,13 +332,13 @@ Turn bytestream into MD5 checksum of old content.
$stream = $stream->punycode_decode;
Punycode decode bytestream, as described in RFC 3492.
Punycode decode bytestream.
=head2 C<punycode_encode>
$stream = $stream->punycode_encode;
Punycode encode bytestream, as described in RFC 3492.
Punycode encode bytestream.
=head2 C<qp_decode>
Expand Down
9 changes: 3 additions & 6 deletions lib/Mojo/Command.pm
Expand Up @@ -52,8 +52,7 @@ sub class_to_file {
my ($self, $class) = @_;
$class =~ s/:://g;
$class =~ s/([A-Z])([A-Z]*)/$1.lc($2)/gex;
decamelize $class;
return $class;
return decamelize $class;
}

sub class_to_path {
Expand Down Expand Up @@ -123,7 +122,7 @@ sub get_all_data {
my $all = $CACHE->{$class} = {};
while (@data) {
my ($name, $content) = splice @data, 0, 2;
b64_decode $content if $name =~ s/\s*\(\s*base64\s*\)$//;
$content = b64_decode $content if $name =~ s/\s*\(\s*base64\s*\)$//;
$all->{$name} = $content;
}

Expand Down Expand Up @@ -202,9 +201,7 @@ sub run {
last if $module = _command("${namespace}::$name");

# DEPRECATED in Smiling Face With Sunglasses!
my $class = $name;
camelize $class;
last if $module = _command("${namespace}::$class");
last if $module = _command("${namespace}::" . camelize $name);
}

# Command missing
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -53,10 +53,7 @@ sub build_boundary {
# Generate and check boundary
my $size = 1;
while (1) {

# Mostly taken from LWP
$boundary = join('', map chr(rand(256)), 1 .. $size * 3);
b64_encode $boundary;
$boundary = b64_encode join('', map chr(rand(256)), 1 .. $size * 3);
$boundary =~ s/\W/X/g;

# Check parts for boundary
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/Cookie.pm
Expand Up @@ -50,10 +50,7 @@ sub _tokenize {

# Value
my $value;
if ($string =~ s/$VALUE_RE//) {
$value = $+{value};
unquote $value;
}
$value = unquote $+{value} if $string =~ s/$VALUE_RE//;

# Token
push @token, [$name, $value];
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Cookie/Request.pm
Expand Up @@ -48,8 +48,7 @@ sub to_string {
my $cookie = $self->name;
my $value = $self->value;
if (defined $value) {
quote $value if $value =~ /[,;"]/;
$cookie .= "=$value";
$cookie .= '=' . ($value =~ /[,;"]/ ? quote($value) : $value);
}
else { $cookie .= '=' }
if (my $path = $self->path) { $cookie .= "; \$Path=$path" }
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Cookie/Response.pm
Expand Up @@ -69,8 +69,7 @@ sub to_string {
my $cookie = $self->name;
my $value = $self->value;
if (defined $value) {
quote $value if $value =~ /[,;"]/;
$cookie .= "=$value";
$cookie .= '=' . ($value =~ /[,;"]/ ? quote($value) : $value);
}
else { $cookie .= '=' }
$cookie .= sprintf "; Version=%d", ($self->version || 1);
Expand Down
18 changes: 6 additions & 12 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -95,7 +95,7 @@ sub parse {

# Decode
my $charset = $self->charset;
decode $charset, $html if $charset;
$html = decode $charset, $html if $charset;

# Tokenize
my $tree = ['root'];
Expand All @@ -106,7 +106,7 @@ sub parse {

# Text
if (length $text) {
html_unescape $text if (index $text, '&') >= 0;
$text = html_unescape $text if (index $text, '&') >= 0;
$self->_text($text, \$current);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ sub parse {
next if $key eq '/';

# Add unescaped value
html_unescape $value if $value && (index $value, '&') >= 0;
$value = html_unescape $value if $value && (index $value, '&') >= 0;
$attrs->{$key} = $value;
}

Expand Down Expand Up @@ -174,8 +174,7 @@ sub render {
my $self = shift;
my $content = $self->_render($self->tree);
my $charset = $self->charset;
encode $charset, $content if $charset;
return $content;
return $charset ? encode($charset, $content) : $content;
}

# "Woah! God is so in your face!
Expand Down Expand Up @@ -277,11 +276,7 @@ sub _render {

# Text (escaped)
my $e = $tree->[0];
if ($e eq 'text') {
my $escaped = $tree->[1];
xml_escape $escaped;
return $escaped;
}
return xml_escape $tree->[1] if $e eq 'text';

# Raw text
return $tree->[1] if $e eq 'raw';
Expand Down Expand Up @@ -321,8 +316,7 @@ sub _render {
push @attrs, $key and next unless defined $value;

# Key and value
xml_escape $value;
push @attrs, qq/$key="$value"/;
push @attrs, qq/$key="/ . xml_escape($value) . '"';
}
my $attrs = join ' ', @attrs;
$content .= " $attrs" if $attrs;
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojo/JSON.pm
Expand Up @@ -75,7 +75,7 @@ sub decode {
last;
}
}
Mojo::Util::decode $encoding, $string;
$string = Mojo::Util::decode $encoding, $string;

# Object or array
my $res = eval {
Expand Down Expand Up @@ -114,9 +114,7 @@ sub decode {

sub encode {
my ($self, $ref) = @_;
my $string = _encode_values($ref);
Mojo::Util::encode 'UTF-8', $string;
return $string;
return Mojo::Util::encode 'UTF-8', _encode_values($ref);
}

sub false {$FALSE}
Expand Down
19 changes: 6 additions & 13 deletions lib/Mojo/Message.pm
Expand Up @@ -514,25 +514,18 @@ sub _parse_formdata {
my $value = $part;

# Unescape
url_unescape $name if $name;
url_unescape $filename if $filename;
$name = url_unescape $name if $name;
$filename = url_unescape $filename if $filename;
if ($charset) {
my $backup = $name;
decode $charset, $name if $name;
$name //= $backup;
$backup = $filename;
decode $charset, $filename if $filename;
$filename //= $backup;
$name = decode($charset, $name) // $name if $name;
$filename = decode($charset, $filename) // $filename if $filename;
}

# Form value
unless ($filename) {
$value = $part->asset->slurp;
if ($charset && !$part->headers->content_transfer_encoding) {
my $backup = $value;
decode $charset, $value;
$value //= $backup;
}
$value = decode($charset, $value) // $value
if $charset && !$part->headers->content_transfer_encoding;
}

push @formdata, [$name, $filename, $value];
Expand Down
10 changes: 3 additions & 7 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -79,15 +79,13 @@ sub fix_headers {

# Basic authorization
if ((my $u = $url->userinfo) && !$headers->authorization) {
b64_encode $u, '';
$headers->authorization("Basic $u");
$headers->authorization('Basic ' . b64_encode($u, ''));
}

# Basic proxy authorization
if (my $proxy = $self->proxy) {
if ((my $u = $proxy->userinfo) && !$headers->proxy_authorization) {
b64_encode $u, '';
$headers->proxy_authorization("Basic $u");
$headers->proxy_authorization('Basic ' . b64_encode($u, ''));
}
}

Expand Down Expand Up @@ -236,9 +234,7 @@ sub _build_start_line {
sub _parse_basic_auth {
my ($self, $header) = @_;
return unless $header =~ /Basic (.+)$/;
my $auth = $1;
b64_decode $auth;
return $auth;
return b64_decode $1;
}

sub _parse_env {
Expand Down

0 comments on commit e3a6590

Please sign in to comment.