File: overload.t

package info (click to toggle)
libnamespace-autoclean-perl 0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: perl: 580; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 479 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use strict;
use warnings;
use Test::More 0.88;

sub main::iter { "welp" };
{
    package Foo;
    use overload
      'bool' => sub(){1},
      '<>' => \&main::iter,
      '0+' => 'numify',
      fallback => 1,
    ;
    use namespace::autoclean;
    sub numify { 219 }
    sub new { bless {}, $_[0] }
}

my $o = Foo->new;
is sprintf('%d', $o), 219, 'method name overload';
is sprintf('%s', $o), 219, 'fallback overload';
is scalar <$o>, 'welp', 'subref overload';

done_testing;