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)
Re:Tricky?
miyagawa on 2008-06-04T03:16:43
Yeah, if Hentai is being used to describe a man, that definitely means a pervert. But when we say "this code is Hentai", it could mean really tricky or voodoo code:) Re:Tricky?
tokuhirom on 2008-06-04T03:21:05
yeah, hentai means sexual things in japanese.
but, sometime, japanese geeks calls 'this is hentai!' about tricky code:)
this is jargonRe:Tricky?
autarch on 2008-06-04T03:31:33
Ah, I see, interesting stuff.
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:Tricky?
Aristotle on 2008-06-05T09:28:34
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:Tricky?
Aristotle on 2008-06-04T03:27:52
Well, it doesn’t seem strange to me to say “this code is perverted.”
Re:Tricky? No, Perverted
mr_bean on 2008-06-05T05:35:56
That may be the case.
But it does seem perverted to call code 'evil.';-)
Substituting 'perverted' and 'evil' for 'strange'
and 'perverted.'
So perhaps 'hentai' just means 'strange'.:-)
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