Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Inheritable configuration options.... but with default values? (updated)

by LanX (Saint)
on Feb 20, 2020 at 17:16 UTC ( [id://11113264]=note: print w/replies, xml ) Need Help??


in reply to Inheritable configuration options.... but with default values?

I can spot at least two issues:

  • You can't inherit private (sic) vars, swap my with our for package vars in the base definition
  • you are doing a re-init which will overwrite old config

you most likely want either

local $cfg{on_error} = "warn";

or

my %cfg=( # now my to avoid overwriting any glob +al %cfg %cfg, # inherited defaults * on_error => "warn", );

(untested)

edit

and in the second case you won't even need inheritance because with pkg-vars you can be explicit

my %cfg=( # now my to avoid overwriting any glob +al %cfg %base::cfg, # inherited defaults * on_error => "warn", );

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

added local and my

update

There are more options ... but the expected behavior is not clear to me ...

To answer this properly we'd need to see an SSCCE

update

*) fixed error in order, swl++

Replies are listed 'Best First'.
Re^2: Inheritable configuration options.... but with default values? (updated)
by swl (Parson) on Feb 20, 2020 at 20:57 UTC

    This order of hash entries will mean the global values override the local.

    It should be:

    my %cfg=( %base::cfg, on_error => "warn", );
      Of course you are totally right.

      I was probably too occupied puzzling about the intended semantics.

      Fixed!

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found