It is annoying to remember YAML.pm
(as well as YAML::Syck
) do not accept file handles as arguments to LoadFile
(but only filenames). So to read a YAML from *DATA
, I wrote a piece of code like this:
use File::Slurp qw( read_file ); use YAML qw( Load Dump );
my $etc = Load(read_file(\*DATA)); # <= that's what matters!!! print Dump($etc);
__DATA__ perl: url: rsync://public.activestate.com/perl-current/ home: base_path: /home/tmp target_dir: perl-current tarball: perl-current.tar.bz2 keep: 1
--- perl: ''
read_file
is called in a list context and "perl:\n"
is the only argument YAML::Load
cares for. The fix:my $etc = Load(scalar read_file(\*DATA));
File::Slurp
trying to be handy and YAML
not being helpful enough. It happens and calls for an improved API.
Re:Decorators?
chromatic on 2007-06-16T18:38:29
You can decorate instances of objects and classes at runtime with roles.
Thanks, applied![Changes for 0.87 (JSON::Syck 0.25) - 2007-06-17]
* New LoadFile and DumpFile functions for JSON::Syck.
* JSON::Syck now actually exports its functions if you ask for it.
* LoadFile and DumpFile now accept IO objects in addition to file names.
Requested by: Adriano Ferreira
Re:YAML::Syck 0.87 - No need for File::Slurp :-)
ferreira on 2007-06-16T17:25:49
Thank you, indeed. Remembering your motto (probably a little distorted by my bad memory): Less code is always better to write and maintain.Re:YAML::Syck 0.87 - No need for File::Slurp :-)
audreyt on 2007-06-16T18:35:14
Well, that's a good motto, though the original was "Best coding = No coding".