Skip Menu |

This queue is for tickets about the MooseX-Declare CPAN distribution.

Report information
The Basics
Id: 49077
Status: open
Priority: 0/
Queue: MooseX-Declare

People
Owner: Nobody in particular
Requestors: komarov.om [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: use overload does not work
Hello. Thanks for great distribution and all your efforts! "use overload" does not work with MooseX::Declare, but works with Moose. MooseX::Declare version 0.27 Moose version 0.89 perl, v5.10.0 built for i686-linux-thread-multi tested on two different linux 2.6 boxes minimal test case: ====================== Aaa.pm: ====================== use MooseX::Declare; class Aaa { has Value => ( is => 'rw', isa => 'Str' ); method asString { return $self->Value; } use overload '""' => sub { $_[ 0 ]->asString }; } ====================== Bbb.pm ====================== package Bbb; use Moose; use MooseX::Method::Signatures; has Value => ( is => 'rw', isa => 'Str' ); method asString { return $self->Value; } use overload '""' => sub { $_[ 0 ]->asString }; 1; ====================== test.pl ====================== use strict; use warnings; use Aaa; use Bbb; my $a = Aaa->new( Value => 'test' ); my $b = Bbb->new( Value => 'test' ); print "$a\n"; print "$b\n"; Here the first output line returns Aaa=HASH(0x8935760) and the second line returns 'test' as expected. If you add "package Aaa;" to the head of Aaa.pm everything is fine.
On Thu Aug 27 17:40:23 2009, https://me.yahoo.com/a/XzqSxipoq.a27wrwYQdLPU7VnHO8ynv91Q--#5d100 wrote: Show quoted text
> Hello. Thanks for great distribution and all your efforts! > > "use overload" does not work with MooseX::Declare, but works with
Moose. Show quoted text
> MooseX::Declare version 0.27 > Moose version 0.89 > perl, v5.10.0 built for i686-linux-thread-multi > tested on two different linux 2.6 boxes > > minimal test case: > > ====================== > Aaa.pm: > ====================== > use MooseX::Declare; > > class Aaa { > has Value => ( is => 'rw', isa => 'Str' ); > > method asString > { > return $self->Value; > } > use overload '""' => sub { $_[ 0 ]->asString }; > } >
Yes, I ran into this problem, too. The following workaround did the trick for me: move overloading outside the class: class Aaa {... as before, minus the overload ...}; package Aaa; use overload '""' => sub { $_[ 0 ]->asString };
Subject: Re: [rt.cpan.org #49077] use overload does not work
Date: Sun, 15 Nov 2009 16:45:42 +0300
To: bug-MooseX-Declare [...] rt.cpan.org
From: Komarov Oleg <komarov.om [...] gmail.com>
On 11/15/2009 11:54 AM, Abhijit Mahabal via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=49077> > > On Thu Aug 27 17:40:23 2009, > https://me.yahoo.com/a/XzqSxipoq.a27wrwYQdLPU7VnHO8ynv91Q--#5d100 wrote: >
>> Hello. Thanks for great distribution and all your efforts! >> >> "use overload" does not work with MooseX::Declare, but works with >>
> Moose. >
>> MooseX::Declare version 0.27 >> Moose version 0.89 >> perl, v5.10.0 built for i686-linux-thread-multi >> tested on two different linux 2.6 boxes >> >> minimal test case: >> >> ====================== >> Aaa.pm: >> ====================== >> use MooseX::Declare; >> >> class Aaa { >> has Value => ( is => 'rw', isa => 'Str' ); >> >> method asString >> { >> return $self->Value; >> } >> use overload '""' => sub { $_[ 0 ]->asString }; >> } >> >>
> Yes, I ran into this problem, too. The following workaround did the > trick for me: move overloading outside the class: > > class Aaa {... as before, minus the overload ...}; > package Aaa; > use overload '""' => sub { $_[ 0 ]->asString }; > >
Yesterday I came across this article: http://blog.woobling.org/2009/11/scoping-of-current-package.html