Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small formatting tweaks
  • Loading branch information
kraih committed Dec 28, 2012
1 parent 0c24468 commit f74cf10
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

3.71 2012-12-28
- Modernized ".travis.yml".
- Improved monkey_patch to patch multiple functions at once. (jberger)
- Improved documentation.

3.70 2012-12-23
Expand Down
14 changes: 9 additions & 5 deletions lib/Mojo/Util.pm
Expand Up @@ -131,10 +131,10 @@ sub md5_bytes { md5(@_) }
sub md5_sum { md5_hex(@_) }

sub monkey_patch {
my ($class, %spec) = @_;
my ($class, %patch) = @_;
no strict 'refs';
no warnings 'redefine';
*{"${class}::$_"} = $spec{$_} for keys %spec;
*{"${class}::$_"} = $patch{$_} for keys %patch;
}

sub punycode_decode {
Expand Down Expand Up @@ -542,11 +542,15 @@ Generate MD5 checksum for string.
=head2 C<monkey_patch>
monkey_patch $package, $name, sub {...}, ... ;
monkey_patch $package, foo => sub {...};
monkey_patch $package, foo => sub {...}, bar => sub {...};
Monkey patch function(s) into package.
Monkey patch functions into package.
monkey_patch 'MyApp', 'hello', sub { say 'Hello!' };
monkey_patch 'MyApp',
one => sub { say 'One!' },
two => sub { say 'Two!' },
three => sub { say 'Three!' };
=head2 C<punycode_decode>
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -36,8 +36,8 @@ sub import {
}
monkey_patch $caller, $_, sub {$app}
for qw(new app);
monkey_patch $caller, 'del', sub { $routes->delete(@_) };
monkey_patch $caller, 'group', sub (&) {
monkey_patch $caller, del => sub { $routes->delete(@_) };
monkey_patch $caller, group => sub (&) {
my $old = $root;
$_[0]->($root = $routes);
($routes, $root) = ($root, $old);
Expand Down
24 changes: 12 additions & 12 deletions lib/ojo.pm
Expand Up @@ -34,23 +34,23 @@ sub import {
a => sub { $caller->can('any')->(@_) and return $UA->app },
b => \&b,
c => \&c,
d => sub { _request($UA->build_tx(DELETE => @_)) },
d => sub { _request($UA->build_tx(DELETE => @_)) },
f => sub { _request($UA->build_form_tx(@_)) },
g => sub { _request($UA->build_tx(GET => @_)) },
h => sub { _request($UA->build_tx(HEAD => @_)) },
j => sub {
my $d = shift;
my $j = Mojo::JSON->new;
return $j->encode($d) if ref $d eq 'ARRAY' || ref $d eq 'HASH';
return $j->decode($d);
},
g => sub { _request($UA->build_tx(GET => @_)) },
h => sub { _request($UA->build_tx(HEAD => @_)) },
n => sub { _request($UA->build_json_tx(@_)) },
o => sub { _request($UA->build_tx(OPTIONS => @_)) },
p => sub { _request($UA->build_tx(POST => @_)) },
p => sub { _request($UA->build_tx(POST => @_)) },
r => sub { $UA->app->dumper(@_) },
t => sub { _request($UA->build_tx(PATCH => @_)) },
u => sub { _request($UA->build_tx(PUT => @_)) },
t => sub { _request($UA->build_tx(PATCH => @_)) },
u => sub { _request($UA->build_tx(PUT => @_)) },
x => sub { Mojo::DOM->new(@_) };
monkey_patch $caller, j => sub {
my $d = shift;
my $j = Mojo::JSON->new;
return $j->encode($d) if ref $d eq 'ARRAY' || ref $d eq 'HASH';
return $j->decode($d);
};
}

sub _request {
Expand Down

0 comments on commit f74cf10

Please sign in to comment.