Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 65b2387a

Von Moritz Bunkus vor mehr als 5 Jahren hinzugefügt

  • ID 65b2387a54494a8cbc1d011602ae3f8d7208ea4d
  • Vorgänger 43f67d0d
  • Nachfolger f93b80e4

Module: gebundletes YAML durch dünnen Wrapper über YAML::XS & YAML ersetzt

Unterschiede anzeigen:

SL/Auth/SessionValue.pm
7 7
use SL::Locale::String ();
8 8

  
9 9
use Scalar::Util qw(weaken);
10
use YAML;
11 10

  
12 11
use SL::DBUtils;
12
use SL::YAML;
13 13

  
14 14
sub new {
15 15
  my ($class, %params) = @_;
......
39 39
  my ($self) = @_;
40 40
  no warnings 'once';
41 41
  local $YAML::Stringify = 1;
42
  return YAML::Dump($self->get);
42
  return SL::YAML::Dump($self->get);
43 43
}
44 44

  
45 45
sub _fetch {
......
58 58
sub _parse {
59 59
  my ($self) = @_;
60 60

  
61
  $self->{value}  = YAML::Load($self->{value}) unless $self->{parsed};
61
  $self->{value}  = SL::YAML::Load($self->{value}) unless $self->{parsed};
62 62
  $self->{parsed} = 1;
63 63

  
64 64
  return $self;
......
71 71

  
72 72
  my %params = ( simple => 1 );
73 73
  eval {
74
    my $data = YAML::Load($value);
74
    my $data = SL::YAML::Load($value);
75 75

  
76 76
    if (ref $data eq 'HASH') {
77 77
      map { $params{$_} = $data->{$_} } keys %{ $data };
SL/BackgroundJob/CsvImport.pm
4 4

  
5 5
use parent qw(SL::BackgroundJob::Base);
6 6

  
7
use YAML ();
8 7
use SL::JSON;
8
use SL::YAML;
9 9
use SL::DB::CsvImportProfile;
10 10

  
11 11
sub create_job {
......
23 23
    type         => 'once',
24 24
    active       => 1,
25 25
    package_name => $package,
26
    data         => YAML::Dump(\%data),
26
    data         => SL::YAML::Dump(\%data),
27 27
  );
28 28

  
29 29
  return $job;
......
33 33
  my ($self) = @_;
34 34

  
35 35
  if (!$self->{profile}) {
36
    my $data = YAML::Load($self->{db_obj}->data);
36
    my $data = SL::YAML::Load($self->{db_obj}->data);
37 37
    $self->{profile} = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id});
38 38
  }
39 39

  
SL/Controller/Draft.pm
9 9
use SL::Request;
10 10
use SL::DB::Draft;
11 11
use SL::DBUtils qw(selectall_hashref_query);
12
use YAML;
12
use SL::YAML;
13 13
use List::Util qw(max);
14 14

  
15 15
use Rose::Object::MakeMethods::Generic (
......
53 53
    module      => $self->module,
54 54
    submodule   => $self->submodule,
55 55
    description => $description,
56
    form        => YAML::Dump($form),
56
    form        => SL::YAML::Dump($form),
57 57
    employee_id => SL::DB::Manager::Employee->current->id,
58 58
  );
59 59

  
......
83 83
    require $allowed_modules{ $self->draft->module };
84 84
  }
85 85
  my $params = delete $::form->{form};
86
  my $new_form = YAML::Load($self->draft->form);
86
  my $new_form = SL::YAML::Load($self->draft->form);
87 87
  $::form->{$_} = $new_form->{$_} for keys %$new_form;
88 88
  $::form->{"draft_$_"} = $self->draft->$_ for qw(id description);
89 89

  
SL/Controller/Order.pm
11 11
use SL::Webdav;
12 12
use SL::File;
13 13
use SL::Util qw(trim);
14
use SL::YAML;
14 15
use SL::DB::Order;
15 16
use SL::DB::Default;
16 17
use SL::DB::Unit;
......
552 553
                 email_body                 => $::form->{email_body},
553 554
               };
554 555

  
555
  my $periodic_invoices_config = YAML::Dump($config);
556
  my $periodic_invoices_config = SL::YAML::Dump($config);
556 557

  
557 558
  my $status = $self->get_periodic_invoices_status($config);
558 559

  
......
1232 1233

  
1233 1234
  $order->assign_attributes(%{$::form->{order}});
1234 1235

  
1235
  if (my $periodic_invoices_config_attrs = $form_periodic_invoices_config ? YAML::Load($form_periodic_invoices_config) : undef) {
1236
  if (my $periodic_invoices_config_attrs = $form_periodic_invoices_config ? SL::YAML::Load($form_periodic_invoices_config) : undef) {
1236 1237
    my $periodic_invoices_config = $order->periodic_invoices_config || $order->periodic_invoices_config(SL::DB::PeriodicInvoicesConfig->new);
1237 1238
    $periodic_invoices_config->assign_attributes(%$periodic_invoices_config_attrs);
1238 1239
  }
......
1765 1766
  my ($yaml_config) = @_;
1766 1767

  
1767 1768
  return if !$yaml_config;
1768
  my $attr = YAML::Load($yaml_config);
1769
  my $attr = SL::YAML::Load($yaml_config);
1769 1770
  return if 'HASH' ne ref $attr;
1770 1771
  return SL::DB::PeriodicInvoicesConfig->new(%$attr);
1771 1772
}
SL/DB/BackgroundJob.pm
11 11
use SL::DB::Manager::BackgroundJob;
12 12

  
13 13
use SL::System::Process;
14
use SL::YAML;
14 15

  
15 16
__PACKAGE__->meta->initialize;
16 17

  
......
76 77
sub data_as_hash {
77 78
  my $self = shift;
78 79

  
79
  $self->data(YAML::Dump($_[0])) if @_;
80
  $self->data(SL::YAML::Dump($_[0])) if @_;
80 81

  
81 82
  return {}                        if !$self->data;
82 83
  return $self->data               if ref($self->{data}) eq 'HASH';
83
  return YAML::Load($self->{data}) if !ref($self->{data});
84
  return SL::YAML::Load($self->{data}) if !ref($self->{data});
84 85
  return {};
85 86
}
86 87

  
87 88
sub set_data {
88 89
  my ($self, %data) = @_;
89 90

  
90
  $self->data(YAML::Dump({
91
  $self->data(SL::YAML::Dump({
91 92
    %{ $self->data_as_hash },
92 93
    %data,
93 94
  }));
SL/DO.pm
37 37
use Carp;
38 38
use List::Util qw(max);
39 39
use Text::ParseWords;
40
use YAML;
41 40

  
42 41
use SL::AM;
43 42
use SL::Common;
......
52 51
use SL::TransNumber;
53 52
use SL::DB;
54 53
use SL::Util qw(trim);
54
use SL::YAML;
55 55

  
56 56
use strict;
57 57

  
......
450 450
                  conv_i($sinfo->{bin_id}));
451 451
        $h_item_stock_id->finish();
452 452
        # write back the id to the form (important if only transfer was clicked (id fk for invoice)
453
        $form->{"stock_${in_out}_$i"} = YAML::Dump($stock_info);
453
        $form->{"stock_${in_out}_$i"} = SL::YAML::Dump($stock_info);
454 454
      }
455 455
      @values = ($form->{"delivery_order_items_id_$i"}, $sinfo->{qty}, $sinfo->{unit}, conv_i($sinfo->{warehouse_id}),
456 456
                 conv_i($sinfo->{bin_id}), $sinfo->{chargenumber}, conv_date($sinfo->{bestbefore}),
......
833 833
        push @{ $requests }, $ref;
834 834
      }
835 835

  
836
      $doi->{"stock_${in_out}"} = YAML::Dump($requests);
836
      $doi->{"stock_${in_out}"} = SL::YAML::Dump($requests);
837 837
    }
838 838

  
839 839
    $sth->finish();
......
1095 1095

  
1096 1096
  my $unpacked;
1097 1097

  
1098
  eval { $unpacked = $params{packed} ? YAML::Load($params{packed}) : []; };
1098
  eval { $unpacked = $params{packed} ? SL::YAML::Load($params{packed}) : []; };
1099 1099

  
1100 1100
  $unpacked = [] if (!$unpacked || ('ARRAY' ne ref $unpacked));
1101 1101

  
SL/IC.pm
37 37

  
38 38
use Data::Dumper;
39 39
use List::MoreUtils qw(all any uniq);
40
use YAML;
41 40

  
42 41
use SL::CVar;
43 42
use SL::DBUtils;
SL/InstallationCheck.pm
73 73
  # Net::SMTP is core since 5.7.3
74 74
  { name => "Net::SMTP::SSL",                      url => "http://search.cpan.org/~cwest/",     debian => 'libnet-smtp-ssl-perl' },
75 75
  { name => "Net::SSLGlue",                        url => "http://search.cpan.org/~sullr/",     debian => 'libnet-sslglue-perl' },
76
  { name => "YAML::XS",                            url => "https://metacpan.org/pod/distribution/YAML-LibYAML/lib/YAML/LibYAML.pod", debian => 'libyaml-libyaml-perl' },
76 77
);
77 78

  
78 79
@developer_modules = (
SL/LXDebug.pm
22 22
use POSIX qw(strftime getpid);
23 23
use Scalar::Util qw(blessed refaddr weaken);
24 24
use Time::HiRes qw(gettimeofday tv_interval);
25
use YAML;
26 25
use SL::Request ();
26
use SL::YAML;
27 27

  
28 28
use strict;
29 29
use utf8;
......
213 213
sub dump_yaml {
214 214
  my ($self, $level, $name, $variable) = @_;
215 215

  
216
  $self->message($level, "dumping ${name}:\n" . YAML::Dump($variable));
216
  $self->message($level, "dumping ${name}:\n" . SL::YAML::Dump($variable));
217 217
}
218 218

  
219 219
sub dump_sql_result {
......
252 252
    return;
253 253
  }
254 254

  
255
  my @texts = map { ref $_ ? YAML::Dump($_) : $_ } ($item1, $item2);
255
  my @texts = map { ref $_ ? SL::YAML::Dump($_) : $_ } ($item1, $item2);
256 256

  
257 257
  $self->message($level, Text::Diff::diff(\$texts[0], \$texts[1], \%params));
258 258
}
SL/Menu.pm
3 3
use strict;
4 4

  
5 5
use SL::Auth;
6
use YAML ();
7 6
use File::Spec;
8 7
use SL::MoreCommon qw(uri_encode);
9

  
10
our $yaml_xs;
11
BEGIN {
12
   $yaml_xs =  eval { require YAML::XS };
13
}
8
use SL::YAML;
14 9

  
15 10
our %menu_cache;
16 11

  
......
29 24
    for my $file (@files) {
30 25
      my $data;
31 26
      eval {
32
        if ($yaml_xs) {
33
          $data = YAML::XS::LoadFile(File::Spec->catfile($path, $file));
34
        } else {
35
          $data = YAML::LoadFile(File::Spec->catfile($path, $file));
36
        }
27
        $data = SL::YAML::LoadFile(File::Spec->catfile($path, $file));
37 28
        1;
38 29
      } or do {
39 30
        die "Error while parsing $file: $@";
SL/MoreCommon.pm
8 8

  
9 9
use Encode ();
10 10
use List::MoreUtils qw(zip);
11
use YAML;
11
use SL::YAML;
12 12

  
13 13
use strict;
14 14

  
......
23 23
    delete $main::form->{$key};
24 24
  }
25 25

  
26
  my $old_form = YAML::Dump($main::form);
26
  my $old_form = SL::YAML::Dump($main::form);
27 27
  $old_form =~ s|!|!:|g;
28 28
  $old_form =~ s|\n|!n|g;
29 29
  $old_form =~ s|\r|!r|g;
......
49 49
  $old_form =~ s|!n|\n|g;
50 50
  $old_form =~ s|![!:]|!|g;
51 51

  
52
  my $new_form = YAML::Load($old_form);
52
  my $new_form = SL::YAML::Load($old_form);
53 53
  map { $form->{$_} = $new_form->{$_} if (!$keep_vars_map{$_}) } keys %{ $new_form };
54 54

  
55 55
  $main::lxdebug->leave_sub();
SL/OE.pm
36 36
package OE;
37 37

  
38 38
use List::Util qw(max first);
39
use YAML;
40 39

  
41 40
use SL::AM;
42 41
use SL::Common;
......
53 52
use SL::TransNumber;
54 53
use SL::Util qw(trim);
55 54
use SL::DB;
55
use SL::YAML;
56 56
use Text::ParseWords;
57 57

  
58 58
use strict;
......
816 816

  
817 817
  return if !$params{oe_id};
818 818

  
819
  my $config = $params{config_yaml} ? YAML::Load($params{config_yaml}) : undef;
819
  my $config = $params{config_yaml} ? SL::YAML::Load($params{config_yaml}) : undef;
820 820
  return if 'HASH' ne ref $config;
821 821

  
822 822
  my $obj  = SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $params{oe_id})
......
836 836
    if ($config_obj) {
837 837
      my $config = { map { $_ => $config_obj->$_ } qw(active terminated periodicity order_value_periodicity start_date_as_date end_date_as_date first_billing_date_as_date extend_automatically_by ar_chart_id
838 838
                                                      print printer_id copies direct_debit send_email email_recipient_contact_id email_recipient_address email_sender email_subject email_body) };
839
      $form->{periodic_invoices_config} = YAML::Dump($config);
839
      $form->{periodic_invoices_config} = SL::YAML::Dump($config);
840 840
    }
841 841
  }
842 842
}
SL/YAML.pm
1
package SL::YAML;
2

  
3
use strict;
4
use warnings;
5

  
6
sub _choose_yaml_module {
7
  return 'YAML::XS' if $INC{'YAML/XS.pm'};
8
  return 'YAML'     if $INC{'YAML.pm'};
9

  
10
  my @err;
11

  
12
  return 'YAML::XS' if eval { require YAML::XS; 1; };
13
  push @err, "Error loading YAML::XS: $@";
14

  
15
  return 'YAML' if eval { require YAML; 1; };
16
  push @err, "Error loading YAML: $@";
17

  
18
  die join("\n", "Couldn't load a YAML module:", @err);
19
}
20

  
21
BEGIN {
22
  our $YAML_Class = _choose_yaml_module();
23
  $YAML_Class->import(qw(Dump Load DumpFile LoadFile));
24
}
25

  
26
sub YAML { our $YAML_Class }
27

  
28
1;
29

  
30
__END__
31

  
32
=pod
33

  
34
=encoding utf8
35

  
36
=head1 NAME
37

  
38
SL::YAML - A thin wrapper around YAML::XS and YAML
39

  
40
=head1 SYNOPSIS
41

  
42
    use SL::YAML;
43

  
44
    my $menu_data = SL::YAML::LoadFile("menus/user/00-erp.yml");
45

  
46
=head1 OVERVIEW
47

  
48
This is a thin wrapper around the YAML::XS and YAML modules. It'll
49
prefer loading YAML::XS if that's found and will fallback to YAML
50
otherwise. It only provides the four functions C<Dump>, C<Load>,
51
C<DumpFile> and C<LoadFile> — just enough to get by for kivitendo.
52

  
53
The functions are direct imports from the imported module. Please see
54
the documentation for YAML::XS or YAML for details.
55

  
56
=head1 AUTHOR
57

  
58
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
59

  
60
=cut
bin/mozilla/acctranscorrections.pl
3 3
use SL::Locale::String qw(t8);
4 4
use SL::User;
5 5
use Data::Dumper;
6
use YAML;
7 6

  
8 7
require "bin/mozilla/common.pl";
9 8

  
bin/mozilla/do.pl
35 35
use List::MoreUtils qw(uniq);
36 36
use List::Util qw(max sum);
37 37
use POSIX qw(strftime);
38
use YAML;
39 38

  
40 39
use SL::DB::DeliveryOrder;
41 40
use SL::DO;
......
44 43
use SL::MoreCommon qw(ary_diff restore_form save_form);
45 44
use SL::ReportGenerator;
46 45
use SL::WH;
46
use SL::YAML;
47 47
use Sort::Naturally ();
48 48
require "bin/mozilla/common.pl";
49 49
require "bin/mozilla/io.pl";
......
1390 1390
    push @{ $stock_info }, { map { $_ => $form->{"${_}_${i}"} } qw(delivery_order_items_stock_id warehouse_id bin_id chargenumber bestbefore qty unit) };
1391 1391
  }
1392 1392

  
1393
  $form->{stock} = YAML::Dump($stock_info);
1393
  $form->{stock} = SL::YAML::Dump($stock_info);
1394 1394

  
1395 1395
  _stock_in_out_set_qty_display($stock_info);
1396 1396

  
......
1485 1485
  my @errors     = DO->check_stock_availability('requests' => $stock_info,
1486 1486
                                                'parts_id' => $form->{parts_id});
1487 1487

  
1488
  $form->{stock} = YAML::Dump($stock_info);
1488
  $form->{stock} = SL::YAML::Dump($stock_info);
1489 1489

  
1490 1490
  if (@errors) {
1491 1491
    $form->{ERRORS} = [];
......
1917 1917
  foreach (@all_requests){
1918 1918
    $i++;
1919 1919
    next unless scalar(%{ $_ });
1920
    $form->{"stock_${prefix}_$i"} = YAML::Dump([$_]);
1920
    $form->{"stock_${prefix}_$i"} = SL::YAML::Dump([$_]);
1921 1921
  }
1922 1922

  
1923 1923
  save(no_redirect => 1); # Wir können auslagern, deshalb beleg speichern
bin/mozilla/oe.pl
44 44
use SL::IS;
45 45
use SL::MoreCommon qw(ary_diff restore_form save_form);
46 46
use SL::ReportGenerator;
47
use SL::YAML;
47 48
use List::MoreUtils qw(uniq any none);
48 49
use List::Util qw(min max reduce sum);
49 50
use Data::Dumper;
......
614 615
      $form->{periodic_invoices_status} = $locale->text('not configured');
615 616

  
616 617
    } else {
617
      my $config                        = YAML::Load($form->{periodic_invoices_config});
618
      my $config                        = SL::YAML::Load($form->{periodic_invoices_config});
618 619
      $form->{periodic_invoices_status} = $config->{active} ? $locale->text('active') : $locale->text('inactive');
619 620
    }
620 621
  }
......
2171 2172
  check_oe_access();
2172 2173

  
2173 2174
  my $config;
2174
  $config = YAML::Load($::form->{periodic_invoices_config}) if $::form->{periodic_invoices_config};
2175
  $config = SL::YAML::Load($::form->{periodic_invoices_config}) if $::form->{periodic_invoices_config};
2175 2176

  
2176 2177
  if ('HASH' ne ref $config) {
2177 2178
    my $lang_id = $::form->{language_id};
......
2237 2238
                 email_body                 => $::form->{email_body},
2238 2239
               };
2239 2240

  
2240
  $::form->{periodic_invoices_config} = YAML::Dump($config);
2241
  $::form->{periodic_invoices_config} = SL::YAML::Dump($config);
2241 2242

  
2242 2243
  $::form->{title} = $::locale->text('Edit the configuration for periodic invoices');
2243 2244
  $::form->header;
doc/modules/README.YAML
1
NAME
2
    YAML - YAML Ain't Markup Language (tm)
3

  
4
SYNOPSIS
5
        use YAML;
6
    
7
        # Load a YAML stream of 3 YAML documents into Perl data structures.
8
        my ($hashref, $arrayref, $string) = Load(<<'...');
9
        ---
10
        name: ingy
11
        age: old
12
        weight: heavy
13
        # I should comment that I also like pink, but don't tell anybody.
14
        favorite colors:
15
            - red
16
            - green
17
            - blue
18
        ---
19
        - Clark Evans
20
        - Oren Ben-Kiki
21
        - Ingy döt Net
22
        --- >
23
        You probably think YAML stands for "Yet Another Markup Language". It
24
        ain't! YAML is really a data serialization language. But if you want
25
        to think of it as a markup, that's OK with me. A lot of people try
26
        to use XML as a serialization format.
27
    
28
        "YAML" is catchy and fun to say. Try it. "YAML, YAML, YAML!!!"
29
        ...
30
    
31
        # Dump the Perl data structures back into YAML.
32
        print Dump($string, $arrayref, $hashref); 
33
    
34
        # YAML::Dump is used the same way you'd use Data::Dumper::Dumper
35
        use Data::Dumper;
36
        print Dumper($string, $arrayref, $hashref); 
37

  
38
DESCRIPTION
39
    The YAML.pm module implements a YAML Loader and Dumper based on the YAML
40
    1.0 specification. <http://www.yaml.org/spec/>
41

  
42
    YAML is a generic data serialization language that is optimized for
43
    human readability. It can be used to express the data structures of most
44
    modern programming languages. (Including Perl!!!)
45

  
46
    For information on the YAML syntax, please refer to the YAML
47
    specification.
48

  
49
WHY YAML IS COOL
50
    YAML is readable for people.
51
        It makes clear sense out of complex data structures. You should find
52
        that YAML is an exceptional data dumping tool. Structure is shown
53
        through indentation, YAML supports recursive data, and hash keys are
54
        sorted by default. In addition, YAML supports several styles of
55
        scalar formatting for different types of data.
56

  
57
    YAML is editable.
58
        YAML was designed from the ground up to be an excellent syntax for
59
        configuration files. Almost all programs need configuration files,
60
        so why invent a new syntax for each one? And why subject users to
61
        the complexities of XML or native Perl code?
62

  
63
    YAML is multilingual.
64
        Yes, YAML supports Unicode. But I'm actually referring to
65
        programming languages. YAML was designed to meet the serialization
66
        needs of Perl, Python, Ruby, Tcl, PHP, Javascript and Java. It was
67
        also designed to be interoperable between those languages. That
68
        means YAML serializations produced by Perl can be processed by
69
        Python.
70

  
71
    YAML is taint safe.
72
        Using modules like Data::Dumper for serialization is fine as long as
73
        you can be sure that nobody can tamper with your data files or
74
        transmissions. That's because you need to use Perl's "eval()"
75
        built-in to deserialize the data. Somebody could add a snippet of
76
        Perl to erase your files.
77

  
78
        YAML's parser does not need to eval anything.
79

  
80
    YAML is full featured.
81
        YAML can accurately serialize all of the common Perl data structures
82
        and deserialize them again without losing data relationships.
83
        Although it is not 100% perfect (no serializer is or can be
84
        perfect), it fares as well as the popular current modules:
85
        Data::Dumper, Storable, XML::Dumper and Data::Denter.
86

  
87
        YAML.pm also has the ability to handle code (subroutine) references
88
        and typeglobs. (Still experimental) These features are not found in
89
        Perl's other serialization modules.
90

  
91
    YAML is extensible.
92
        The YAML language has been designed to be flexible enough to solve
93
        it's own problems. The markup itself has 3 basic construct which
94
        resemble Perl's hash, array and scalar. By default, these map to
95
        their Perl equivalents. But each YAML node also supports a tagging
96
        mechanism (type system) which can cause that node to be interpreted
97
        in a completely different manner. That's how YAML can support object
98
        serialization and oddball structures like Perl's typeglob.
99

  
100
YAML IMPLEMENTATIONS IN PERL
101
    This module, YAML.pm, is really just the interface module for YAML
102
    modules written in Perl. The basic interface for YAML consists of two
103
    functions: "Dump" and "Load". The real work is done by the modules
104
    YAML::Dumper and YAML::Loader.
105

  
106
    Different YAML module distributions can be created by subclassing
107
    YAML.pm and YAML::Loader and YAML::Dumper. For example, YAML-Simple
108
    consists of YAML::Simple YAML::Dumper::Simple and YAML::Loader::Simple.
109

  
110
    Why would there be more than one implementation of YAML? Well, despite
111
    YAML's offering of being a simple data format, YAML is actually very
112
    deep and complex. Implementing the entirety of the YAML specification is
113
    a daunting task.
114

  
115
    For this reason I am currently working on 3 different YAML
116
    implementations.
117

  
118
    YAML
119
        The main YAML distribution will keeping evolving to support the
120
        entire YAML specification in pure Perl. This may not be the fastest
121
        or most stable module though. Currently, YAML.pm has lots of known
122
        bugs. It is mostly a great tool for dumping Perl data structures to
123
        a readable form.
124

  
125
    YAML::Lite
126
        The point of YAML::Lite is to strip YAML down to the 90% that people
127
        use most and offer that in a small, fast, stable, pure Perl form.
128
        YAML::Lite will simply die when it is asked to do something it
129
        can't.
130

  
131
    YAML::Syck
132
        "libsyck" is the C based YAML processing library used by the Ruby
133
        programming language (and also Python, PHP and Pugs). YAML::Syck is
134
        the Perl binding to "libsyck". It should be very fast, but may have
135
        problems of its own. It will also require C compilation.
136

  
137
        NOTE: Audrey Tang has actually completed this module and it works
138
        great and is 10 times faster than YAML.pm.
139

  
140
    In the future, there will likely be even more YAML modules. Remember,
141
    people other than Ingy are allowed to write YAML modules!
142

  
143
FUNCTIONAL USAGE
144
    YAML is completely OO under the hood. Still it exports a few useful top
145
    level functions so that it is dead simple to use. These functions just
146
    do the OO stuff for you. If you want direct access to the OO API see the
147
    documentation for YAML::Dumper and YAML::Loader.
148

  
149
  Exported Functions
150
    The following functions are exported by YAML.pm by default. The reason
151
    they are exported is so that YAML works much like Data::Dumper. If you
152
    don't want functions to be imported, just use YAML with an empty import
153
    list:
154

  
155
        use YAML ();
156

  
157
    Dump(list-of-Perl-data-structures)
158
        Turn Perl data into YAML. This function works very much like
159
        Data::Dumper::Dumper(). It takes a list of Perl data strucures and
160
        dumps them into a serialized form. It returns a string containing
161
        the YAML stream. The structures can be references or plain scalars.
162

  
163
    Load(string-containing-a-YAML-stream)
164
        Turn YAML into Perl data. This is the opposite of Dump. Just like
165
        Storable's thaw() function or the eval() function in relation to
166
        Data::Dumper. It parses a string containing a valid YAML stream into
167
        a list of Perl data structures.
168

  
169
  Exportable Functions
170
    These functions are not exported by default but you can request them in
171
    an import list like this:
172

  
173
        use YAML qw'freeze thaw Bless';
174

  
175
    freeze() and thaw()
176
        Aliases to Dump() and Load() for Storable fans. This will also allow
177
        YAML.pm to be plugged directly into modules like POE.pm, that use
178
        the freeze/thaw API for internal serialization.
179

  
180
    DumpFile(filepath, list)
181
        Writes the YAML stream to a file instead of just returning a string.
182

  
183
    LoadFile(filepath)
184
        Reads the YAML stream from a file instead of a string.
185

  
186
    Bless(perl-node, [yaml-node | class-name])
187
        Associate a normal Perl node, with a yaml node. A yaml node is an
188
        object tied to the YAML::Node class. The second argument is either a
189
        yaml node that you've already created or a class (package) name that
190
        supports a yaml_dump() function. A yaml_dump() function should take
191
        a perl node and return a yaml node. If no second argument is
192
        provided, Bless will create a yaml node. This node is not returned,
193
        but can be retrieved with the Blessed() function.
194

  
195
        Here's an example of how to use Bless. Say you have a hash
196
        containing three keys, but you only want to dump two of them.
197
        Furthermore the keys must be dumped in a certain order. Here's how
198
        you do that:
199

  
200
            use YAML qw(Dump Bless);
201
            $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'};
202
            print Dump $hash;
203
            Bless($hash)->keys(['banana', 'apple']);
204
            print Dump $hash;
205

  
206
        produces:
207

  
208
            ---
209
            apple: good
210
            banana: bad
211
            cauliflower: ugly
212
            ---
213
            banana: bad
214
            apple: good
215

  
216
        Bless returns the tied part of a yaml-node, so that you can call the
217
        YAML::Node methods. This is the same thing that YAML::Node::ynode()
218
        returns. So another way to do the above example is:
219

  
220
            use YAML qw(Dump Bless);
221
            use YAML::Node;
222
            $hash = {apple => 'good', banana => 'bad', cauliflower => 'ugly'};
223
            print Dump $hash;
224
            Bless($hash);
225
            $ynode = ynode(Blessed($hash));
226
            $ynode->keys(['banana', 'apple']);
227
            print Dump $hash;
228

  
229
        Note that Blessing a Perl data structure does not change it anyway.
230
        The extra information is stored separately and looked up by the
231
        Blessed node's memory address.
232

  
233
    Blessed(perl-node)
234
        Returns the yaml node that a particular perl node is associated with
235
        (see above). Returns undef if the node is not (YAML) Blessed.
236

  
237
GLOBAL OPTIONS
238
    YAML options are set using a group of global variables in the YAML
239
    namespace. This is similar to how Data::Dumper works.
240

  
241
    For example, to change the indentation width, do something like:
242

  
243
        local $YAML::Indent = 3;
244

  
245
    The current options are:
246

  
247
    DumperClass
248
        You can override which module/class YAML uses for Dumping data.
249

  
250
    LoaderClass
251
        You can override which module/class YAML uses for Loading data.
252

  
253
    Indent
254
        This is the number of space characters to use for each indentation
255
        level when doing a Dump(). The default is 2.
256

  
257
        By the way, YAML can use any number of characters for indentation at
258
        any level. So if you are editing YAML by hand feel free to do it
259
        anyway that looks pleasing to you; just be consistent for a given
260
        level.
261

  
262
    SortKeys
263
        Default is 1. (true)
264

  
265
        Tells YAML.pm whether or not to sort hash keys when storing a
266
        document.
267

  
268
        YAML::Node objects can have their own sort order, which is usually
269
        what you want. To override the YAML::Node order and sort the keys
270
        anyway, set SortKeys to 2.
271

  
272
    Stringify
273
        Default is 0. (false)
274

  
275
        Objects with string overloading should honor the overloading and
276
        dump the stringification of themselves, rather than the actual
277
        object's guts.
278

  
279
    UseHeader
280
        Default is 1. (true)
281

  
282
        This tells YAML.pm whether to use a separator string for a Dump
283
        operation. This only applies to the first document in a stream.
284
        Subsequent documents must have a YAML header by definition.
285

  
286
    UseVersion
287
        Default is 0. (false)
288

  
289
        Tells YAML.pm whether to include the YAML version on the
290
        separator/header.
291

  
292
            --- %YAML:1.0
293

  
294
    AnchorPrefix
295
        Default is ''.
296

  
297
        Anchor names are normally numeric. YAML.pm simply starts with '1'
298
        and increases by one for each new anchor. This option allows you to
299
        specify a string to be prepended to each anchor number.
300

  
301
    UseCode
302
        Setting the UseCode option is a shortcut to set both the DumpCode
303
        and LoadCode options at once. Setting UseCode to '1' tells YAML.pm
304
        to dump Perl code references as Perl (using B::Deparse) and to load
305
        them back into memory using eval(). The reason this has to be an
306
        option is that using eval() to parse untrusted code is, well,
307
        untrustworthy.
308

  
309
    DumpCode
310
        Determines if and how YAML.pm should serialize Perl code references.
311
        By default YAML.pm will dump code references as dummy placeholders
312
        (much like Data::Dumper). If DumpCode is set to '1' or 'deparse',
313
        code references will be dumped as actual Perl code.
314

  
315
        DumpCode can also be set to a subroutine reference so that you can
316
        write your own serializing routine. YAML.pm passes you the code ref.
317
        You pass back the serialization (as a string) and a format
318
        indicator. The format indicator is a simple string like: 'deparse'
319
        or 'bytecode'.
320

  
321
    LoadCode
322
        LoadCode is the opposite of DumpCode. It tells YAML if and how to
323
        deserialize code references. When set to '1' or 'deparse' it will
324
        use "eval()". Since this is potentially risky, only use this option
325
        if you know where your YAML has been.
326

  
327
        LoadCode can also be set to a subroutine reference so that you can
328
        write your own deserializing routine. YAML.pm passes the
329
        serialization (as a string) and a format indicator. You pass back
330
        the code reference.
331

  
332
    UseBlock
333
        YAML.pm uses heuristics to guess which scalar style is best for a
334
        given node. Sometimes you'll want all multiline scalars to use the
335
        'block' style. If so, set this option to 1.
336

  
337
        NOTE: YAML's block style is akin to Perl's here-document.
338

  
339
    UseFold
340
        If you want to force YAML to use the 'folded' style for all
341
        multiline scalars, then set $UseFold to 1.
342

  
343
        NOTE: YAML's folded style is akin to the way HTML folds text, except
344
        smarter.
345

  
346
    UseAliases
347
        YAML has an alias mechanism such that any given structure in memory
348
        gets serialized once. Any other references to that structure are
349
        serialized only as alias markers. This is how YAML can serialize
350
        duplicate and recursive structures.
351

  
352
        Sometimes, when you KNOW that your data is nonrecursive in nature,
353
        you may want to serialize such that every node is expressed in full.
354
        (ie as a copy of the original). Setting $YAML::UseAliases to 0 will
355
        allow you to do this. This also may result in faster processing
356
        because the lookup overhead is by bypassed.
357

  
358
        THIS OPTION CAN BE DANGEROUS. *If* your data is recursive, this
359
        option *will* cause Dump() to run in an endless loop, chewing up
360
        your computers memory. You have been warned.
361

  
362
    CompressSeries
363
        Default is 1.
364

  
365
        Compresses the formatting of arrays of hashes:
366

  
367
            -
368
              foo: bar
369
            - 
370
              bar: foo
371

  
372
        becomes:
373

  
374
            - foo: bar
375
            - bar: foo
376

  
377
        Since this output is usually more desirable, this option is turned
378
        on by default.
379

  
380
YAML TERMINOLOGY
381
    YAML is a full featured data serialization language, and thus has its
382
    own terminology.
383

  
384
    It is important to remember that although YAML is heavily influenced by
385
    Perl and Python, it is a language in its own right, not merely just a
386
    representation of Perl structures.
387

  
388
    YAML has three constructs that are conspicuously similar to Perl's hash,
389
    array, and scalar. They are called mapping, sequence, and string
390
    respectively. By default, they do what you would expect. But each
391
    instance may have an explicit or implicit tag (type) that makes it
392
    behave differently. In this manner, YAML can be extended to represent
393
    Perl's Glob or Python's tuple, or Ruby's Bigint.
394

  
395
    stream
396
        A YAML stream is the full sequence of unicode characters that a YAML
397
        parser would read or a YAML emitter would write. A stream may
398
        contain one or more YAML documents separated by YAML headers.
399

  
400
            ---
401
            a: mapping
402
            foo: bar
403
            ---
404
            - a
405
            - sequence
406

  
407
    document
408
        A YAML document is an independent data structure representation
409
        within a stream. It is a top level node. Each document in a YAML
410
        stream must begin with a YAML header line. Actually the header is
411
        optional on the first document.
412

  
413
            ---
414
            This: top level mapping
415
            is:
416
                - a
417
                - YAML
418
                - document
419

  
420
    header
421
        A YAML header is a line that begins a YAML document. It consists of
422
        three dashes, possibly followed by more info. Another purpose of the
423
        header line is that it serves as a place to put top level tag and
424
        anchor information.
425

  
426
            --- !recursive-sequence &001
427
            - * 001
428
            - * 001
429

  
430
    node
431
        A YAML node is the representation of a particular data stucture.
432
        Nodes may contain other nodes. (In Perl terms, nodes are like
433
        scalars. Strings, arrayrefs and hashrefs. But this refers to the
434
        serialized format, not the in-memory structure.)
435

  
436
    tag This is similar to a type. It indicates how a particular YAML node
437
        serialization should be transferred into or out of memory. For
438
        instance a Foo::Bar object would use the tag 'perl/Foo::Bar':
439

  
440
            - !perl/Foo::Bar
441
                foo: 42
442
                bar: stool
443

  
444
    collection
445
        A collection is the generic term for a YAML data grouping. YAML has
446
        two types of collections: mappings and sequences. (Similar to hashes
447
        and arrays)
448

  
449
    mapping
450
        A mapping is a YAML collection defined by unordered key/value pairs
451
        with unique keys. By default YAML mappings are loaded into Perl
452
        hashes.
453

  
454
            a mapping:
455
                foo: bar
456
                two: times two is 4
457

  
458
    sequence
459
        A sequence is a YAML collection defined by an ordered list of
460
        elements. By default YAML sequences are loaded into Perl arrays.
461

  
462
            a sequence:
463
                - one bourbon
464
                - one scotch
465
                - one beer
466

  
467
    scalar
468
        A scalar is a YAML node that is a single value. By default YAML
469
        scalars are loaded into Perl scalars.
470

  
471
            a scalar key: a scalar value
472

  
473
        YAML has many styles for representing scalars. This is important
474
        because varying data will have varying formatting requirements to
475
        retain the optimum human readability.
476

  
477
    plain scalar
478
        A plain sclar is unquoted. All plain scalars are automatic
479
        candidates for "implicit tagging". This means that their tag may be
480
        determined automatically by examination. The typical uses for this
481
        are plain alpha strings, integers, real numbers, dates, times and
482
        currency.
483

  
484
            - a plain string
485
            - -42
486
            - 3.1415
487
            - 12:34
488
            - 123 this is an error
489

  
490
    single quoted scalar
491
        This is similar to Perl's use of single quotes. It means no escaping
492
        except for single quotes which are escaped by using two adjacent
493
        single quotes.
494

  
495
            - 'When I say ''\n'' I mean "backslash en"'
496

  
497
    double quoted scalar
498
        This is similar to Perl's use of double quotes. Character escaping
499
        can be used.
500

  
501
            - "This scalar\nhas two lines, and a bell -->\a"
502

  
503
    folded scalar
504
        This is a multiline scalar which begins on the next line. It is
505
        indicated by a single right angle bracket. It is unescaped like the
506
        single quoted scalar. Line folding is also performed.
507

  
508
            - > 
509
             This is a multiline scalar which begins on
510
             the next line. It is indicated by a single
511
             carat. It is unescaped like the single
512
             quoted scalar. Line folding is also
513
             performed.
514

  
515
    block scalar
516
        This final multiline form is akin to Perl's here-document except
517
        that (as in all YAML data) scope is indicated by indentation.
518
        Therefore, no ending marker is required. The data is verbatim. No
519
        line folding.
520

  
521
            - |
522
                QTY  DESC          PRICE  TOTAL
523
                ---  ----          -----  -----
524
                  1  Foo Fighters  $19.95 $19.95
525
                  2  Bar Belles    $29.95 $59.90
526

  
527
    parser
528
        A YAML processor has four stages: parse, load, dump, emit.
529

  
530
        A parser parses a YAML stream. YAML.pm's Load() function contains a
531
        parser.
532

  
533
    loader
534
        The other half of the Load() function is a loader. This takes the
535
        information from the parser and loads it into a Perl data structure.
536

  
537
    dumper
538
        The Dump() function consists of a dumper and an emitter. The dumper
539
        walks through each Perl data structure and gives info to the
540
        emitter.
541

  
542
    emitter
543
        The emitter takes info from the dumper and turns it into a YAML
544
        stream.
545

  
546
        NOTE: In YAML.pm the parser/loader and the dumper/emitter code are
547
        currently very closely tied together. In the future they may be
548
        broken into separate stages.
549

  
550
    For more information please refer to the immensely helpful YAML
551
    specification available at <http://www.yaml.org/spec/>.
552

  
553
ysh - The YAML Shell
554
    The YAML distribution ships with a script called 'ysh', the YAML shell.
555
    ysh provides a simple, interactive way to play with YAML. If you type in
556
    Perl code, it displays the result in YAML. If you type in YAML it turns
557
    it into Perl code.
558

  
559
    To run ysh, (assuming you installed it along with YAML.pm) simply type:
560

  
561
        ysh [options]
562

  
563
    Please read the "ysh" documentation for the full details. There are lots
564
    of options.
565

  
566
BUGS & DEFICIENCIES
567
    If you find a bug in YAML, please try to recreate it in the YAML Shell
568
    with logging turned on ('ysh -L'). When you have successfully reproduced
569
    the bug, please mail the LOG file to the author (ingy@cpan.org).
570

  
571
    WARNING: This is still *ALPHA* code. Well, most of this code has been
572
    around for years...
573

  
574
    BIGGER WARNING: YAML.pm has been slow in the making, but I am committed
575
    to having top notch YAML tools in the Perl world. The YAML team is close
576
    to finalizing the YAML 1.1 spec. This version of YAML.pm is based off of
577
    a very old pre 1.0 spec. In actuality there isn't a ton of difference,
578
    and this YAML.pm is still fairly useful. Things will get much better in
579
    the future.
580

  
581
RESOURCES
582
    <http://lists.sourceforge.net/lists/listinfo/yaml-core> is the mailing
583
    list. This is where the language is discussed and designed.
584

  
585
    <http://www.yaml.org> is the official YAML website.
586

  
587
    <http://www.yaml.org/spec/> is the YAML 1.0 specification.
588

  
589
    <http://yaml.kwiki.org> is the official YAML wiki.
590

  
591
SEE ALSO
592
    See YAML::Syck. Fast!
593

  
594
AUTHOR
595
    Ingy döt Net <ingy@cpan.org>
596

  
597
    is resonsible for YAML.pm.
598

  
599
    The YAML serialization language is the result of years of collaboration
600
    between Oren Ben-Kiki, Clark Evans and Ingy döt Net. Several others
601
    have added help along the way.
602

  
603
COPYRIGHT
604
    Copyright (c) 2005, 2006. Ingy döt Net. All rights reserved. Copyright
605
    (c) 2001, 2002, 2005. Brian Ingerson. All rights reserved.
606

  
607
    This program is free software; you can redistribute it and/or modify it
608
    under the same terms as Perl itself.
609

  
610
    See <http://www.perl.com/perl/misc/Artistic.html>
611

  
modules/override/YAML.pm
1
package YAML;
2
our $VERSION = '1.14';
3

  
4
use YAML::Mo;
5

  
6
use Exporter;
7
push @YAML::ISA, 'Exporter';
8
our @EXPORT = qw{ Dump Load };
9
our @EXPORT_OK = qw{ freeze thaw DumpFile LoadFile Bless Blessed };
10

  
11
use YAML::Node; # XXX This is a temp fix for Module::Build
12

  
13
# XXX This VALUE nonsense needs to go.
14
use constant VALUE => "\x07YAML\x07VALUE\x07";
15

  
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")};
21

  
22
sub Dump {
23
    my $yaml = YAML->new;
24
    $yaml->dumper_class($YAML::DumperClass)
25
        if $YAML::DumperClass;
26
    return $yaml->dumper_object->dump(@_);
27
}
28

  
29
sub Load {
30
    my $yaml = YAML->new;
31
    $yaml->loader_class($YAML::LoaderClass)
32
        if $YAML::LoaderClass;
33
    return $yaml->loader_object->load(@_);
34
}
35

  
36
{
37
    no warnings 'once';
38
    # freeze/thaw is the API for Storable string serialization. Some
39
    # modules make use of serializing packages on if they use freeze/thaw.
40
    *freeze = \ &Dump;
41
    *thaw   = \ &Load;
42
}
43

  
44
sub DumpFile {
45
    my $OUT;
46
    my $filename = shift;
47
    if (ref $filename eq 'GLOB') {
48
        $OUT = $filename;
49
    }
50
    else {
51
        my $mode = '>';
52
        if ($filename =~ /^\s*(>{1,2})\s*(.*)$/) {
53
            ($mode, $filename) = ($1, $2);
54
        }
55
        open $OUT, $mode, $filename
56
          or YAML::Mo::Object->die('YAML_DUMP_ERR_FILE_OUTPUT', $filename, $!);
57
    }
58
    binmode $OUT, ':utf8';  # if $Config{useperlio} eq 'define';
59
    local $/ = "\n"; # reset special to "sane"
60
    print $OUT Dump(@_);
61
}
62

  
63
sub LoadFile {
64
    my $IN;
65
    my $filename = shift;
66
    if (ref $filename eq 'GLOB') {
67
        $IN = $filename;
68
    }
69
    else {
70
        open $IN, '<', $filename
71
          or YAML::Mo::Object->die('YAML_LOAD_ERR_FILE_INPUT', $filename, $!);
72
    }
73
    binmode $IN, ':utf8';  # if $Config{useperlio} eq 'define';
74
    return Load(do { local $/; <$IN> });
75
}
76

  
77
sub init_action_object {
78
    my $self = shift;
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;
86
    return $object;
87
}
88

  
89
my $global = {};
90
sub Bless {
91
    require YAML::Dumper::Base;
92
    YAML::Dumper::Base::bless($global, @_)
93
}
94
sub Blessed {
95
    require YAML::Dumper::Base;
96
    YAML::Dumper::Base::blessed($global, @_)
97
}
98
sub global_object { $global }
99

  
100
1;
modules/override/YAML/Any.pm
1
use strict; use warnings;
2
package YAML::Any;
3
our $VERSION = '1.14';
4

  
5
use Exporter ();
6

  
7
@YAML::Any::ISA       = 'Exporter';
8
@YAML::Any::EXPORT    = qw(Dump Load);
9
@YAML::Any::EXPORT_OK = qw(DumpFile LoadFile);
10

  
11
my @dump_options = qw(
12
    UseCode
13
    DumpCode
14
    SpecVersion
15
    Indent
16
    UseHeader
17
    UseVersion
18
    SortKeys
19
    AnchorPrefix
20
    UseBlock
21
    UseFold
22
    CompressSeries
23
    InlineSeries
24
    UseAliases
25
    Purity
26
    Stringify
27
);
28

  
29
my @load_options = qw(
30
    UseCode
31
    LoadCode
32
);
33

  
34
my @implementations = qw(
35
    YAML::XS
36
    YAML::Syck
37
    YAML::Old
38
    YAML
39
    YAML::Tiny
40
);
41

  
42
sub import {
43
    __PACKAGE__->implementation;
44
    goto &Exporter::import;
45
}
46

  
47
sub Dump {
48
    no strict 'refs';
49
    no warnings 'once';
50
    my $implementation = __PACKAGE__->implementation;
51
    for my $option (@dump_options) {
52
        my $var = "$implementation\::$option";
53
        my $value = $$var;
54
        local $$var;
55
        $$var = defined $value ? $value : ${"YAML::$option"};
56
    }
57
    return &{"$implementation\::Dump"}(@_);
58
}
59

  
60
sub DumpFile {
61
    no strict 'refs';
62
    no warnings 'once';
63
    my $implementation = __PACKAGE__->implementation;
64
    for my $option (@dump_options) {
65
        my $var = "$implementation\::$option";
66
        my $value = $$var;
67
        local $$var;
68
        $$var = defined $value ? $value : ${"YAML::$option"};
69
    }
70
    return &{"$implementation\::DumpFile"}(@_);
71
}
72

  
73
sub Load {
74
    no strict 'refs';
75
    no warnings 'once';
76
    my $implementation = __PACKAGE__->implementation;
77
    for my $option (@load_options) {
78
        my $var = "$implementation\::$option";
79
        my $value = $$var;
80
        local $$var;
81
        $$var = defined $value ? $value : ${"YAML::$option"};
82
    }
83
    return &{"$implementation\::Load"}(@_);
84
}
85

  
86
sub LoadFile {
87
    no strict 'refs';
88
    no warnings 'once';
89
    my $implementation = __PACKAGE__->implementation;
90
    for my $option (@load_options) {
91
        my $var = "$implementation\::$option";
92
        my $value = $$var;
93
        local $$var;
94
        $$var = defined $value ? $value : ${"YAML::$option"};
95
    }
96
    return &{"$implementation\::LoadFile"}(@_);
97
}
98

  
99
sub order {
100
    return @YAML::Any::_TEST_ORDER
101
        if @YAML::Any::_TEST_ORDER;
102
    return @implementations;
103
}
104

  
105
sub implementation {
106
    my @order = __PACKAGE__->order;
107
    for my $module (@order) {
108
        my $path = $module;
109
        $path =~ s/::/\//g;
110
        $path .= '.pm';
111
        return $module if exists $INC{$path};
112
        eval "require $module; 1" and return $module;
113
    }
114
    croak("YAML::Any couldn't find any of these YAML implementations: @order");
115
}
116

  
117
sub croak {
118
    require Carp;
119
    Carp::croak(@_);
120
}
121

  
122
1;
modules/override/YAML/Dumper.pm
1
package YAML::Dumper;
2

  
3
use YAML::Mo;
4
extends 'YAML::Dumper::Base';
5

  
6
use YAML::Dumper::Base;
7
use YAML::Node;
8
use YAML::Types;
9
use Scalar::Util qw();
10

  
11
# Context constants
12
use constant KEY       => 3;
13
use constant BLESSED   => 4;
14
use constant FROMARRAY => 5;
15
use constant VALUE     => "\x07YAML\x07VALUE\x07";
16

  
17
# Common YAML character sets
18
my $ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]';
19
my $LIT_CHAR    = '|';
20

  
21
#==============================================================================
22
# OO version of Dump. YAML->new->dump($foo);
23
sub dump {
24
    my $self = shift;
25
    $self->stream('');
26
    $self->document(0);
27
    for my $document (@_) {
28
        $self->{document}++;
29
        $self->transferred({});
30
        $self->id_refcnt({});
31
        $self->id_anchor({});
32
        $self->anchor(1);
33
        $self->level(0);
34
        $self->offset->[0] = 0 - $self->indent_width;
35
        $self->_prewalk($document);
36
        $self->_emit_header($document);
37
        $self->_emit_node($document);
38
    }
39
    return $self->stream;
40
}
41

  
42
# Every YAML document in the stream must begin with a YAML header, unless
43
# there is only a single document and the user requests "no header".
44
sub _emit_header {
45
    my $self = shift;
46
    my ($node) = @_;
47
    if (not $self->use_header and
48
        $self->document == 1
49
       ) {
50
        $self->die('YAML_DUMP_ERR_NO_HEADER')
51
          unless ref($node) =~ /^(HASH|ARRAY)$/;
52
        $self->die('YAML_DUMP_ERR_NO_HEADER')
53
          if ref($node) eq 'HASH' and keys(%$node) == 0;
54
        $self->die('YAML_DUMP_ERR_NO_HEADER')
55
          if ref($node) eq 'ARRAY' and @$node == 0;
56
        # XXX Also croak if aliased, blessed, or ynode
57
        $self->headless(1);
58
        return;
59
    }
60
    $self->{stream} .= '---';
61
# XXX Consider switching to 1.1 style
62
    if ($self->use_version) {
63
#         $self->{stream} .= " #YAML:1.0";
64
    }
65
}
66

  
67
# Walk the tree to be dumped and keep track of its reference counts.
68
# This function is where the Dumper does all its work. All type
69
# transfers happen here.
70
sub _prewalk {
71
    my $self = shift;
72
    my $stringify = $self->stringify;
73
    my ($class, $type, $node_id) = $self->node_info(\$_[0], $stringify);
74

  
75
    # Handle typeglobs
76
    if ($type eq 'GLOB') {
77
        $self->transferred->{$node_id} =
78
          YAML::Type::glob->yaml_dump($_[0]);
79
        $self->_prewalk($self->transferred->{$node_id});
80
        return;
81
    }
82

  
83
    # Handle regexps
84
    if (ref($_[0]) eq 'Regexp') {
85
        return;
86
    }
87

  
88
    # Handle Purity for scalars.
89
    # XXX can't find a use case yet. Might be YAGNI.
90
    if (not ref $_[0]) {
91
        $self->{id_refcnt}{$node_id}++ if $self->purity;
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.

Auch abrufbar als: Unified diff