7 push @YAML::ISA, 'Exporter';
8 our @EXPORT = qw{ Dump Load };
9 our @EXPORT_OK = qw{ freeze thaw DumpFile LoadFile Bless Blessed };
11 use YAML::Node; # XXX This is a temp fix for Module::Build
13 # XXX This VALUE nonsense needs to go.
14 use constant VALUE => "\x07YAML\x07VALUE\x07";
16 # YAML Object Properties
17 has dumper_class => default => sub {'YAML::Dumper'};
18 has loader_class => default => sub {'YAML::Loader'};
19 has dumper_object => default => sub {$_[0]->init_action_object("dumper")};
20 has loader_object => default => sub {$_[0]->init_action_object("loader")};
24 $yaml->dumper_class($YAML::DumperClass)
25 if $YAML::DumperClass;
26 return $yaml->dumper_object->dump(@_);
31 $yaml->loader_class($YAML::LoaderClass)
32 if $YAML::LoaderClass;
33 return $yaml->loader_object->load(@_);
38 # freeze/thaw is the API for Storable string serialization. Some
39 # modules make use of serializing packages on if they use freeze/thaw.
47 if (ref $filename eq 'GLOB') {
52 if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) {
53 ($mode, $filename) = ($1, $2);
55 open $OUT, $mode, $filename
56 or YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT', $filename, $!);
58 binmode $OUT, ':utf8'; # if $Config{useperlio} eq 'define';
59 local $/ = "\n"; # reset special to "sane"
66 if (ref $filename eq 'GLOB') {
70 open $IN, '<', $filename
71 or YAML::Mo::Object->die('YAML_LOAD_ERR_FILE_INPUT', $filename, $!);
73 binmode $IN, ':utf8'; # if $Config{useperlio} eq 'define';
74 return Load(do { local $/; <$IN> });
77 sub init_action_object {
79 my $object_class = (shift) . '_class';
80 my $module_name = $self->$object_class;
81 eval "require $module_name";
82 $self->die("Error in require $module_name - $@")
83 if $@ and "$@" !~ /Can't locate/;
84 my $object = $self->$object_class->new;
85 $object->set_global_options;
91 require YAML::Dumper::Base;
92 YAML::Dumper::Base::bless($global, @_)
95 require YAML::Dumper::Base;
96 YAML::Dumper::Base::blessed($global, @_)
98 sub global_object { $global }