in reply to Re: Method autovivification with variable values?
in thread Method autovivification with variable values?

'Fraid not. That would have to be done at the interface level, which would end up requiring said tests to be written into a dozen modules. I'm hoping for something which can be written into the same module as the $configs is defined, and thus can be used w/o editing the interface layer.

Thanks for the try!

What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

Replies are listed 'Best First'.
Re3Method autovivification with variable values?
by dragonchild (Archbishop) on Sep 28, 2001 at 20:47 UTC
    You can do a tie to $configs, so that whenever a FETCH is done, it checks for existence and auto-vivifies before returning the value.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      But will it automatically give it a value that depends upon the variable it was called with?

      What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
        What do you mean by "the variable it was called with"?

        Either $configs is a hashref or it's an object. If it's a hashref, you can tie it. If it's an object, you should be controlling the accesses into the data using some set of methods. In fact, all tie does is give you the same control over access you have with objects and let you use that control with "normal" variable types like scalars and hashes.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.