blob: 5b3d93c17227c2020e302ea5c8bb339810ddf6b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
use strict;
use lib -e 't' ? 't' : 'test';
use TestYAML tests => 6;
no_diff;
package Foo;
use overload '""' => \&stringy;
sub stringy { 'Hello mate!' }
sub new { bless { 'Hello' => 'mate!' }, shift };
package main;
my $foo = Foo->new;
my $stringy_dump = <<'';
--- Hello mate!
my $object_dump = <<'';
--- !!perl/hash:Foo
Hello: mate!
my $yaml;
$yaml = Dump($foo);
is $yaml, $object_dump, "Global stringification default dump";
$YAML::Stringify = 1;
$yaml = Dump($foo);
is $yaml, $stringy_dump, "Global stringification enabled dump";
$YAML::Stringify = 0;
$yaml = Dump($foo);
is $yaml, $object_dump, "Global stringification disabled dump";
require YAML::Dumper;
my $dumper = YAML::Dumper->new;
$yaml = $dumper->dump($foo);
is $yaml, $object_dump, "Local stringification default dump";
$dumper->stringify(1);
$yaml = $dumper->dump($foo);
is $yaml, $stringy_dump, "Local stringification enabled dump";
$dumper->stringify(0);
$yaml = $dumper->dump($foo);
is $yaml, $object_dump, "Local stringification disabled dump";
|