Al-HUWAITI Shell
Al-huwaiti


Server : Apache
System : Linux dedi-14684855.grupobig.com 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : grupo692 ( 1004)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /home/.cpan/build/YAML-LibYAML-v0.902.0-0/t/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/.cpan/build/YAML-LibYAML-v0.902.0-0/t/blessed.t
use FindBin '$Bin';
use lib $Bin;
use TestYAMLTests tests => 11;
use YAML::XS ();

my $unblessed = YAML::XS::Load('!!perl/array:Foo [23]');
is(ref $unblessed, 'ARRAY', "No objects by default");

$YAML::XS::LoadBlessed = 1;

filters {
    perl => 'eval',
    yaml => 'load_yaml',
};
my $test = get_block_by_name("Blessed Hashes and Arrays");

my $hash = $test->perl;
my $hash2 = $test->yaml;

# is_deeply is broken and doesn't check blessings
is_deeply $hash2, $hash, "Load " . $test->name;

is ref($hash2->{foo}), 'Foo::Bar',
    "Object at 'foo' is blessed 'Foo::Bar'";
is ref($hash2->{bar}), 'Foo::Bar',
    "Object at 'bar' is blessed 'Foo::Bar'";
is ref($hash2->{one}), 'BigList',
    "Object at 'one' is blessed 'BigList'";
is ref($hash2->{two}), 'BigList',
    "Object at 'two' is blessed 'BigList'";

my $yaml = Dump($hash2);

is $yaml, $test->yaml_dump, "Dumping " . $test->name . " works";

######
$test = get_block_by_name("Blessed Scalar Ref");
my $array = $test->perl;
my $array2 = $test->yaml;

# is_deeply is broken and doesn't check blessings
is_deeply $array2, $array, "Load " . $test->name;

is ref($array2->[0]), 'Blessed',
    "Scalar ref is class name 'Blessed'";

like "$array2->[0]", qr/=SCALAR\(/,
    "Got a scalar ref";

$yaml = Dump($array2);

is $yaml, $test->yaml_dump, "Dumping " . $test->name . " works";

__DATA__
=== Blessed Hashes and Arrays
+++ yaml
foo: !!perl/hash:Foo::Bar {}
bar: !!perl/hash:Foo::Bar
  bass: bawl
one: !!perl/array:BigList []
two: !!perl/array:BigList
- lola
- alol
+++ perl
+{
    foo => (bless {}, "Foo::Bar"),
    bar => (bless {bass => 'bawl'}, "Foo::Bar"),
    one => (bless [], "BigList"),
    two => (bless [lola => 'alol'], "BigList"),
};
+++ yaml_dump
---
bar: !!perl/hash:Foo::Bar
  bass: bawl
foo: !!perl/hash:Foo::Bar {}
one: !!perl/array:BigList []
two: !!perl/array:BigList
- lola
- alol

=== Blessed Scalar Ref
+++ yaml
---
- !!perl/scalar:Blessed hey hey
+++ perl
my $x = 'hey hey';
[bless \$x, 'Blessed'];
+++ yaml_dump
---
- !!perl/scalar:Blessed hey hey

Al-HUWAITI Shell