[Linux-aus] Moose, JSON Question

David Lloyd lloy0076 at adam.com.au
Sun Jan 4 20:18:00 EST 2009


(Daniel said the things that have a 0 or 1 level of quotation depeding  
on what index you start arrays):
>>>>    1. But the caveat is that they don't do what you expect them to
>>>>       do...
>>> They don't do what *you* expect them to do — your examples did
>>> exactly what I expected. ;) More seriously, this is the standard  
>>> Perl
>>> behaviour, not anything to do with Moose or otherwise.
>> Sometimes Perl gives me the willies, to use the vernacular.
> Heh.  Fair enough.  I confess I never really understood that, myself,
> since the behaviour is almost always pretty consistent, but the DWIM
> features can sometimes be very confusing, even to experts. :)


>> I must have missed that when I did:
>> perl -Ilib -MTestJSOn -e -d 0
>> ...
>> DB<?> S
>> [lots of methods]
> Odd.  I don't know if there is anything special that might hide them
> from the debugger 'S' output—I have never actually used the Perl
> debugger, to be honest, so don't know what quirks it might hide.

I still don't recall seeing it. Then again I am special. Not  
necessarily in the right ways.

> Well, you should probably think of a Moose "role" as a Java  
> "interface",
> kind of, except that it comes with implementation as well.

Yeah, a mixin type thing. An interface with some implementation that  
could be overridden.

>>>>    1. That is, in this case I did "use JSON;" and caused  
>>>> "from_json"
>>>>       and "to_json" to materialise - if I have an actual object
>>>>       (TestJSON->new()) I can call them but as shown the behaviour
>>>>       is suboptimal
>>> Your calling convention is wrong: the JSON methods need to have  
>>> their
>>> data as the first argument, and calling them as methods means that  
>>> they
>>> don't.
>> I understood that much - hopefully my commentary indicated that I'd
>> detected that they were being called as class methods rather than
>> POPMs (Plain Old Perl Methods).
>>> The summary is, don't do that.  Use your wrapper methods. ;)
>> I was kind of hoping that Moose or the Perl Object system would
>> insulate me from this type of shenanigans.
> Those "shenanigans" are the basic ingredients of method calling in  
> Perl;
> would you really want an OO system that completely and utterly changed
> the calling convention of the language?


I wanted a Java like object system where imported "things" couldn't be  
seen from the outside. And it's worse - it's class specific random  
things (if you don't use a method, it seems whatever whacko export  
method JSON uses doesn't expose it) - so the behaviour changes  
depending on what you've written EVEN IF it's not called.

That said, do you think it's possible to write a "Moose::Strict"  
module that:

* Only exposed methods explicitly defined as "subs" on that class, its  
children or mixins/roles

I suspect it's possible.


More information about the linux-aus mailing list