Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

tokuhirom (7396)

tokuhirom
  (email not shown publicly)
http://d.hatena.ne.jp/tokuhirom/

Journal of tokuhirom (7396)

Tuesday June 03, 2008
09:20 PM

Moose::Role + overload

[ #36582 ]
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)
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • __PACKAGE__->meta->set_overload(q{""} => sub { shift->stringify } ); is much better?
  • 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 ;)
    • 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 :)
    • yeah, hentai means sexual things in japanese. but, sometime, japanese geeks calls 'this is hentai!' about tricky code :) this is jargon
      • 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!
      • 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… :-)

    • Well, it doesn’t seem strange to me to say “this code is perverted.”

      • 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

  • ã¦ã™ã¨!