Subject: | overloading not working with fields |
With this in Hello.pm:
package Hello;
use overload qw/""/ => 'foo';
sub new { bless {}, shift; }
sub foo {$self = shift; return $self->{foo}};
1;
Overloading is working:
main::(-e:1): 0
DB<1> use Hello
DB<2> $a=Hello->new
DB<3> x $a->{foo}=34
0 34
DB<4> x $a
0 Hello=HASH(0x934d360)
'foo' => 34
DB<5> x "$a"
0 34
DB<6>
But with the use of Spiffy -base, and field 'foo':
package Hello;
use Spiffy -base;
use overload qw/""/ => 'foo';
sub new { bless {}, shift; }
field 'foo';
1;
We get:
main::(-e:1): 0
DB<1> use Hello
DB<2> $a=Hello->new
DB<3> $a->foo(34)
DB<4> x $a
0 Hello=HASH(0xa37f54c)
'foo' => 34
DB<5> x "$a"
0 ''
DB<6> x $a->foo
0 undef
DB<7> x $a
0 Hello=HASH(0xa37f54c)
'foo' => undef
DB<8>
Although without field 'foo':
package Hello;
use Spiffy -base;
use overload qw/""/ => 'foo';
sub new { bless {}, shift; }
sub foo {$self = shift; return $self->{foo}};
1;
It is OK:
main::(-e:1): 0
DB<1> use Hello
DB<2> $a=Hello->new
DB<3> $a->{foo} = 34
DB<4> x $a
0 Hello=HASH(0x9801174)
'foo' => 34
DB<5> x "$a"
0 34
DB<6> x $a->foo
0 34
DB<7>
So fields don't seem to allow overloading.
This is perl, v5.8.3 built for i386-linux-thread-multi
[greg@momotaro Games-Tournament-Swiss]$ uname -a
Linux momotaro.chinmin.edu.tw 2.6.5-1.358 #1 Sat May 8 09:04:50
EDT 2004 i686 i686 i386 GNU/Linux [