Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Reconfiguration of classes in an "inheritable" manner

by Fletch (Bishop)
on Jun 23, 2022 at 21:02 UTC ( [id://11145006]=note: print w/replies, xml ) Need Help??


in reply to Reconfiguration of classes in an "inheritable" manner

Maybe not reading it right, but I'd think you could just stash the config values in a class variable (so %my::base::_config or %my::branch_A::_config). You'd need something to walk up the @ISA to retrieve values if they're not present in the class of the instance (handwaving here and untested ):

sub _fetch { my( $class, $key ) = @_; no strict q{refs}; my $opts = \%{ ref($class) . q{::_config} }; if( exists $opts->{ $key } ) { return $opts->{ $key }; } else { return SUPER->_fetch( $key ); } } sub configure { my( $class, %opts ) = @_; no strict q{refs}; my $opts = \%{ $class . q{::_config} }; for my ($k, $v) ( each %opts ) { $opts->{ $k } = $v; } return; }

Edit: Adding stub configure

The cake is a lie.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found