Tuesday June 03, 2008
09:20 PM
Moose::Role + overload
follow code does not works.
package MyApp::Role::Stringify;
use overload
q{""} => sub { shift->stringify }
;
requires 'stringify';
package MyApp;
with 'MyApp::Role::Stringify';
has dat ( is => 'ro', isa => 'Str' );
sub stringify { shift->dat }
because, the architecture of overload.pm is
export method named '()'
export method named '(""'
Moose::Role applies coderefs, that defined at Role.Exported methods are not import to applicant.
one way to resolve this problem is:
package MyApp::Role::Stringify;
use Moose::Role;
__PACKAGE__->meta->add_package_symbol('&()' => sub { }); # dummy
__PACKAGE__->meta->add_package_symbol('&(""' => sub { shift->stringify });
but, this is not so smart :( this is Hentai way(hentai means tricky in japanese)
tokuhirom (Score:1)
Tricky? (Score:2)
Re: (Score:2)
Re: (Score:1)
Re: (Score:2)
Obviously, my limited knowledge of Japanese has an extra weird bent because I've mostly learned things by watching anime, which isn't exactly a good example of normal Japanese life.
I was kind of disappointed that on my trips to Tokyo there hasn't been one single giant robot battle on the streets. Not one!
Re: (Score:1)
On second thought, this reminds me of “bukakke,” which AFAIK is innocuous in Japanese, but was adopted in Western languages for one particular and relatively unusual meaning… :-)
Re: (Score:1)
Well, it doesn’t seem strange to me to say “this code is perverted.”
Re:Tricky? No, Perverted (Score:1)
But it does seem perverted to call code 'evil.'
Substituting 'perverted' and 'evil' for 'strange'
and 'perverted.'
So perhaps 'hentai' just means 'strange'.
Excellent MooseX:: module (Score:1)
I think ->meta->add_overload() would make an excellent MooseX:: module. I did not add it to core Moose because I am not a big fan of overload, and after having added the support into Class::Trait I was not wanting to experience it again :)
- Stevan
test (Score:1)