Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re^5: Class::InsideOut - yet another riff on inside out objects.

by John M. Dlugosz (Monsignor)
on Dec 20, 2002 at 17:36 UTC ( #221476=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Class::InsideOut - yet another riff on inside out objects.
in thread Class::InsideOut - yet another riff on inside out objects.

I mean per-accessor: you want some (most) but not all. Or you want those for public things but not private things.


Comment on Re: Re^5: Class::InsideOut - yet another riff on inside out objects.
Re^6: Class::InsideOut - yet another riff on inside out objects.
by Aristotle (Chancellor) on Dec 20, 2002 at 18:38 UTC
    That's something an attribute could very elegantly handle:
    my %Mode : Field(rw); # generate accessor + mutator my %Status : Field(ro); # generate only accessor my %Connection : Field; # generate nothing
    I'm also thinking it would be nice if one could also write my %Mode : Field(rw custom);
    which would not create an accessor, but would test for the existence of one and complain if it didn't find one. That way the code becomes self documenting. Maybe a do-nothing private attribute would be nice to that end as well.

    Makeshifts last the longest.

      my %Mode : Field(rw); # generate accessor + mutator my %Status : Field(ro); # generate only accessor my %Connection : Field; # generate nothing

      Like this a lot.

      my %Mode : Field(rw custom);

      I'd probably avoid this since it's not something that you can guarantee. You could have an accessor/mutator - but with a different name. You could also have a method that wasn't an accessor/mutator with the same name. In either case the "custom" documentation would end up being inaccurate.

        You could have an accessor/mutator - but with a different name. You could also have a method that wasn't an accessor/mutator with the same name.
        Good catch - pity.. it would have been nice.

        Makeshifts last the longest.

        Actually, I was originally going to suggest some syntax that lets one define their own accessor code. Unfortunately it seems not to be possible to pass anything but strings to the attribute routine, so passing a coderef is out.

        But I guess the generator can check whether a method with the mutator's/accessor's projected name already exists and skip generation if so. It would be easy to define some extra syntax for telling the attribute the desired names.

        # separate methods my %Foo : Field(r:get_field w:set_field); # combined mut/acc method my %Foo : Field(rw:quux);
        It would be nice there is some more syntax so the autogenerated accessor can do limited parameter validation without one having to write custom ones for simple cases like 'HASH' eq ref $_1. For more complex cases, the could be something like: my %Foo : Field(rw prew:bar postw:baz postr:quux);

        Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://221476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2014-09-21 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls