Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by Aristotle (Chancellor)
on Dec 22, 2002 at 01:31 UTC ( #221699=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^8: Class::InsideOut - yet another riff on inside out objects.
Select or Download Code
Re^9: Class::InsideOut - yet another riff on inside out objects.
by adrianh (Chancellor) on Dec 22, 2002 at 11:17 UTC

    Hmmm... this sort of stuff falls over the 80/20 sweet spot for me. I would probably add a hook so sub-classes can customise how accessors/mutators are created. That way you could have:

    package Foo; use base(Class::InsideOut::SetterGetter); sub new { bless [], shift }; my %Foo : Field(rw); package Bar; use base(Class::InsideOut::Lvalue); sub new { bless [], shift }; my %Bar : Field(rw); package main; my $foo = Foo->new; my $bar = Bar->new; $foo->set_foo(12); print $foo->get_foo, "\n"; $bar->bar = 42; print $bar->bar, "\n";
      That's cool too - actually, I like it better.

      Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-12-28 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls