On Tue, May 18, 2010 at 10:11:41PM -0700, Kate Yoak wrote: > Hi all, > > I am using an ORM, which creates methods for my class using globs, in place. > > e.g. __PACKAGE__->has_a('foo'...); > > now I have a foo() method defined in my namespace. > > I thought that I could use method modifiers to supplement the created methods: > > around foo => sub{ > ..... > }; > > This failed to work, complaining that the method was not found in the class's > inheritance hierarchy. Is this the expected behavior? > > The workaround is easy, changing the original foo to _foo and making > hand-written foo() call it. I am just curious to understand how things are > supposed to work. :-) > > Cheers, > Kate
Class::MOP (and so Moose) recognizes methods as code symbols in a package that also have a valid subname (as with Sub::Name). This is because methods declared with the 'sub' keyword automatically get the appropriate subname, and functions exported into your package by assigning to globs don't, and so function exports (from things like Try::Tiny, List::Util, etc) don't get seen as methods. If you're using something that's actually intending to export methods, you'll have to add the subname yourself, either (as Moose does) by doing it inside the exporter, like use Sub::Name; *foo = subname 'foo' => sub { ... }; or I believe you can also add a subname after the fact with something like use Sub::Name; subname 'foo', \&foo; although I'm not entirely sure about that one. -doy