Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use more methods, fewer hash accesses

  • Loading branch information...
commit 08d9f4ca6ecb379e026f81e6a5def1766f96dace 1 parent 0e87dbe
@rjbs authored
Showing with 6 additions and 11 deletions.
  1. +2 −4 t/lib/Class.pm
  2. +4 −7 t/lib/Instance.pm
View
6 t/lib/Class.pm
@@ -10,9 +10,7 @@ my %STATIC = (
);
my %UNIVERSAL = (
- new => sub {
- bless { __class__ => $_[0] } => $_[0]->instance_class,
- },
+ new => sub { bless { __class__ => $_[0] } => $_[0]->instance_class, },
name => sub { $_[0]->{name} },
base => sub { $_[0]->{base} },
new_subclass => sub {
@@ -33,7 +31,7 @@ my %UNIVERSAL = (
my $curr = $self;
while ($curr) {
return 1 if $curr == $super;
- $curr = $curr->{base};
+ $curr = $curr->base;
}
return;
},
View
11 t/lib/Instance.pm
@@ -11,10 +11,7 @@ my %STATIC = (
my %UNIVERSAL = (
class => sub { $_[0]->{__class__} }, # shout out to my homies in python
- isa => sub {
- my $class = $_[0]->class;
- return $class->derives_from($_[1]);
- },
+ isa => sub { return $_[0]->class->derives_from($_[1]); },
);
use metamethod sub {
@@ -33,16 +30,16 @@ use metamethod sub {
while ($curr) {
# Sadly, this has to be a hash deref until the tests pass once.
- my $methods = $curr->{instance_methods};
+ my $methods = $curr->instance_methods;
$code = $methods->{$method_name}, last
if exists $methods->{$method_name};
- $curr = $curr->{base};
+ $curr = $curr->base;
}
unless ($code ||= $UNIVERSAL{$method_name}) {
my $msg = sprintf "no instance method %s on %s(%s)",
- $method_name, ref($invocant), $invocant->{__class__}{name};
+ $method_name, ref($invocant), $invocant->{__class__}->name;
die $msg;
}
Please sign in to comment.
Something went wrong with that request. Please try again.