in reply to Re: What's the best way to use Any YAML (not YAML::Any)
in thread What's the best way to use Any YAML (not YAML::Any)
Thanks. A couple of comments:
- Checking for Dump/Load is prudent, but all of the listed YAML modules implement the common Dump/Load API, so I don't think it's absolutely necessary.
-
The check for Dump/Load in your last version assumes the included module uses @EXPORT. I wouldn't rely on that, as there are alternates to Exporter which don't use that, and while these modules might currently use it, that behavior is not in the API. If they switch to something else, this'll break.
A better way might be to perform an explicit import, e.g. something like
or, if you can trust that the function isn't AUTOLOADED, look at the module's namespace for the functioneval { $yaml_class->import( 'Dump'); 1; } or croak( "Can't find Dump in $yaml_class\n" );
The only foolproof method is to just wait for a runtime error:Package::Stash->new( $yaml_class )->has_symbol( '&Dump' ) or croak( "Can't find Dump in $yaml_class\n" );my $Dump = $yaml_class . "::Dump"; [... later in the code ...] my $var = eval { &$Dump(...) } or croak( "bad return or Dump not imple +mented\n" );
In Section
Seekers of Perl Wisdom