Skip to content

Instantly share code, notes, and snippets.

@kga
Created Jan 20, 2018
Embed
What would you like to do?
use strict;
use warnings;
use utf8;
package Foo {
use overload (
bool => sub { warn 'this is bool' },
q{""} => sub { warn 'this is stringify' },
);
sub new { bless {}, shift }
}
my $foo = Foo->new;
warn 'hi' if $foo;
warn 'hoi' if defined $foo;
my $bar = $foo;
my $baz = $foo . 'fooray';
@kga
Copy link
Author

kga commented Jan 20, 2018

15:30 > perl overload.pl
this is bool at overload.pl line 7.
hi at overload.pl line 16.
hoi at overload.pl line 17.
this is stringify at overload.pl line 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment