Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: Class::Accessor and Damian's PBP

by cbrandtbuffalo (Deacon)
on Feb 23, 2006 at 12:47 UTC ( #532266=note: print w/replies, xml ) Need Help??

in reply to Re: Class::Accessor and Damian's PBP
in thread Class::Accessor and Damian's PBP

If you have so many accessible properties that you need to generate accessors for them, you may need to re-think your design.

I'm working on a configuration module, so accessors and data are the primary purpose of the module. You can see some background in Configuration Best Practices for Web Apps.

Even if you don't have many, though, I would argue the good kind of Laziness should drive you to use tools to avoid cut and paste. Even with just a few accessors, the code often ends up being largely cut and pasted, so using a module to automate the process is still a nice idea.

Replies are listed 'Best First'.
Re^3: Class::Accessor and Damian's PBP
by Roy Johnson (Monsignor) on Feb 23, 2006 at 19:54 UTC
    After playing around in several directions, I realized that it's trivially easy to generate default accessors, which may be why there are so many modules for it (although it makes me wonder why there are any).
    for my $property (qw(several members defined public)) { no strict 'refs'; *{"get_$property"} = sub { (shift)->{$property} }; *{"set_$property"} = sub { (shift)->{$property} = $_[0] }; }

    Caution: Contents may have been coded under pressure.
      You got it. I took at look and that's almost exactly what Class::Accessor does.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2023-03-20 20:06 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.