File: 17_overload.t

package info (click to toggle)
libhash-fieldhash-perl 0.15-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,249; ansic: 207; makefile: 10
file content (42 lines) | stat: -rw-r--r-- 678 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl
# https://rt.cpan.org/Public/Bug/Display.html?id=58030
use strict;
use warnings;
use Test::More;

use if $] < 5.010_000, 'Test::More', skip_all => 'Perl 5.8.8 triggers stringification';

my $stringified = 0;
{
    package Foo;

    use overload '""' => \&stringify;

    sub new { bless {}, shift @_ };

    sub stringify {
        #use Carp qw(cluck); cluck "stringified";
        $stringified++;
        'foo';
    };

}

use Hash::FieldHash qw[ fieldhash ];

fieldhash my %h;

my $x = Foo->new;
my $y = Foo->new;

$h{$x} = 'X';
$h{$y} = 'Y';

#use Data::Dumper; print Dumper \%h;

is $h{$x}, 'X';
is $h{$y}, 'Y';

is $stringified, 0, 'not stringified';

done_testing;