Moose::Role + overload

tokuhirom on 2008-06-04T02:20:03

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

tokuhirom on 2008-06-04T02:53:41

__PACKAGE__->meta->set_overload(q{""} => sub { shift->stringify } );

is much better?

Tricky?

autarch on 2008-06-04T03:02:52

Hentai often gets translated as pervert in anime, at least, though I know the root (hen) means strange. But us foreign anime geeks generally associate the word hentai with some sort of sexual deviancy ;)

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 jargon

Re: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'. :-)

Excellent MooseX:: module

Stevan on 2008-06-04T07:01:12

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

tokuhirom on 2009-07-01T03:20:04

ã¦ã™ã¨!