Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: using AUTOLOAD to access read-only data structures

by shmem (Canon)
on Jun 02, 2011 at 06:27 UTC ( #907756=note: print w/replies, xml ) Need Help??

in reply to Re: using AUTOLOAD to access read-only data structures
in thread using AUTOLOAD to access read-only data structures

It can't be done from within, since the method call is out of the scope of that package. It's like saying
perl -le '$foo = "Blorf"; $foo->quux' Can't locate object method "quux" via package "Blorf" (perhaps you for +got to load "Blorf"?) at -e line 1.

Replies are listed 'Best First'.
Re^3: using AUTOLOAD to access read-only data structures
by ikegami (Pope) on Jun 02, 2011 at 06:33 UTC
    $foo doesn't hold an object that stringifies to Blorf or throws a better error on method call.
      Thanks, got it. Sometimes I'm slow.

      update: something like that would do:

      ... sub import { shift; $config or $config = XMLin(shift) if @_; $XSConf::strict = shift if @_; return; # don't give $config away } .... ref $thing and $token = $thing or return bless \$thing, XS +Conf::Str; } } return $package; } package XSConf::Str; use overload '""' => \&str, fallback => 1; sub str { ${$_[0]} } our $AUTOLOAD; sub AUTOLOAD { return if $AUTOLOAD eq 'XSConf::Str::DESTROY'; my @caller = caller; die "you cannot invoke the method '$AUTOLOAD' on the string '$_[0] +'" . " at $caller[1] line $caller[2]\n" if $XSConf::strict; $_[0]; } 1;

      update: added $XSConf::strict, caller and die

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://907756]
Corion idly wonders if there is a way to produce ordered .yml files. I want to accept YAML for a configuration file format, but I also want to generate (for debugging/start) a sample configuration file from the current configuration.
[Corion]: Ideally, that configuration file would have some order of the keys, but I'm not sure whether/how YAML supports ordered output.
[Corion]: Basically I have this metadata and generating a purposeful example is much better if the output is ordered in the same way the documentation is ordered

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-01-16 12:00 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (149 votes). Check out past polls.