Skip to content

Commit

Permalink
added basic support for Perl 5.20 signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 20, 2014
1 parent 3b04921 commit f0ff29c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
18 changes: 18 additions & 0 deletions lib/Mojo/Base.pm
Expand Up @@ -41,6 +41,12 @@ sub import {
# Mojo modules are strict!
$_->import for qw(strict warnings utf8);
feature->import(':5.10');

# Signatures for Perl 5.20+
if ($^V >= 5.020000) {
feature->import('signatures');
warnings->unimport('experimental::signatures');
}
}

sub attr {
Expand Down Expand Up @@ -137,13 +143,21 @@ All three forms save a lot of typing.
use warnings;
use utf8;
use feature ':5.10';
if ($^V >= 5.020000) {
feature->import('signatures');
warnings->unimport('experimental::signatures');
}
use IO::Handle ();
# use Mojo::Base -base;
use strict;
use warnings;
use utf8;
use feature ':5.10';
if ($^V >= 5.020000) {
feature->import('signatures');
warnings->unimport('experimental::signatures');
}
use IO::Handle ();
use Mojo::Base;
push @ISA, 'Mojo::Base';
Expand All @@ -154,6 +168,10 @@ All three forms save a lot of typing.
use warnings;
use utf8;
use feature ':5.10';
if ($^V >= 5.020000) {
feature->import('signatures');
warnings->unimport('experimental::signatures');
}
use IO::Handle ();
require SomeBaseClass;
push @ISA, 'SomeBaseClass';
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -11,6 +11,7 @@ use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use List::Util 'min';
use MIME::Base64 qw(decode_base64 encode_base64);
use Scalar::Util 'set_prototype';
use Symbol 'delete_package';
use Time::HiRes ();

Expand Down Expand Up @@ -278,11 +279,12 @@ sub squish {
return $str;
}

sub steady_time () {
sub steady_time {
MONOTONIC
? Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC())
: Time::HiRes::time;
}
BEGIN { set_prototype \&steady_time, '' }

sub tablify {
my $rows = shift;
Expand Down
13 changes: 8 additions & 5 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -6,6 +6,7 @@ use File::Basename qw(basename dirname);
use File::Spec::Functions 'catdir';
use Mojo::UserAgent::Server;
use Mojo::Util 'monkey_patch';
use Scalar::Util 'set_prototype';

sub import {

Expand Down Expand Up @@ -38,11 +39,13 @@ sub import {
monkey_patch $caller, $_, sub {$app}
for qw(new app);
monkey_patch $caller, del => sub { $routes->delete(@_) };
monkey_patch $caller, group => sub (&) {
(my $old, $root) = ($root, $routes);
shift->();
($routes, $root) = ($root, $old);
};
monkey_patch $caller, group => set_prototype(
sub {
(my $old, $root) = ($root, $routes);
shift->();
($routes, $root) = ($root, $old);
} => '&'
);
monkey_patch $caller,
helper => sub { $app->helper(@_) },
hook => sub { $app->hook(@_) },
Expand Down
6 changes: 5 additions & 1 deletion lib/ojo.pm
Expand Up @@ -7,6 +7,7 @@ use Mojo::Collection 'c';
use Mojo::DOM;
use Mojo::JSON 'j';
use Mojo::Util qw(dumper monkey_patch);
use Scalar::Util 'set_prototype';

# Silent one-liners
$ENV{MOJO_LOG_LEVEL} ||= 'fatal';
Expand All @@ -16,6 +17,7 @@ sub import {
# Mojolicious::Lite
my $caller = caller;
eval "package $caller; use Mojolicious::Lite; 1" or die $@;
Mojo::Base->import(-strict);
my $ua = $caller->app->ua;
$ua->server->app->hook(around_action => sub { local $_ = $_[1]; $_[0]->() });

Expand All @@ -31,7 +33,7 @@ sub import {
g => sub { _request($ua, 'GET', @_) },
h => sub { _request($ua, 'HEAD', @_) },
j => \&j,
n => sub (&@) { say STDERR timestr timeit($_[1] // 1, $_[0]) },
n => set_prototype(\&_n, '&@'),
o => sub { _request($ua, 'OPTIONS', @_) },
p => sub { _request($ua, 'POST', @_) },
r => \&dumper,
Expand All @@ -40,6 +42,8 @@ sub import {
x => sub { Mojo::DOM->new(@_) };
}

sub _n { say STDERR timestr timeit($_[1] // 1, $_[0]) }

sub _request {
my $ua = shift;

Expand Down

0 comments on commit f0ff29c

Please sign in to comment.