Skip to content

Instantly share code, notes, and snippets.

@notbenh
Created January 13, 2011 19:20
Show Gist options
  • Save notbenh/778427 to your computer and use it in GitHub Desktop.
Save notbenh/778427 to your computer and use it in GitHub Desktop.
proof that I don't understand overload at all
#!/usr/bin/perl
use strict;
use warnings;
use Test::Most qw{no_plan};
use Carp::Always;
BEGIN{ print qq{\n} for 1..10};
#-----------------------------------------------------------------
#
#-----------------------------------------------------------------
BEGIN {
package My::Test;
use Moose;
use overload '+' => sub{ 'moo' };
sub zing {
my ($self,$one,$two) = @_;
return 'cow' if $one eq 'moo';
return $one + $two;
}
};
my $t = My::Test->new;
is 1 + 2, 3, q{overload not exported};
is $t->zing(1,2), 'moo', q{overload is scoped correctly};
is $t->zing(1+2), 'cow', q{how I wish overload worked};
__END__
ok 1 - overload not exported
not ok 2 - overload is scoped correctly
# Failed test 'overload is scoped correctly'
# at /home/benh/tmp/overload.t line 25.
# got: '3'
# expected: 'moo'
Use of uninitialized value $two in addition (+) at /home/benh/tmp/overload.t line 19
My::Test::zing('My::Test=HASH(0x8cb9f28)', 3) called at /home/benh/tmp/overload.t line 26
not ok 3 - how I wish overload worked
# Failed test 'how I wish overload worked'
# at /home/benh/tmp/overload.t line 26.
# got: '3'
# expected: 'cow'
1..3
# Looks like you failed 2 tests of 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment