Skip to content

Instantly share code, notes, and snippets.

@kga
Created January 20, 2018 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kga/f24a72dfe9b2f58b9fdbc7bd9ec98377 to your computer and use it in GitHub Desktop.
Save kga/f24a72dfe9b2f58b9fdbc7bd9ec98377 to your computer and use it in GitHub Desktop.
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