🌌 SpectraShell

🌌 SpectraShell

Current path: home/.cpan/build/YAML-LibYAML-v0.902.0-0/t/



⬆️ Go up: YAML-LibYAML-v0.902.0-0

📄 Viewing: 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



📁

ABOUT US

SAI Connections is an autism treatment and therapy centre in Mumbai, India. Since 2004, we have been helping individuals with autism spectrum disorder, ADHD and other learning disabilities to develop the necessary skills needed to live an empowered life. We work towards empowering individuals to live a life with dignity that every human deserves.

 

Read More

SERVICES OFFERED

Our spacious centre is the perfect location for children with autism to develop skills which help them adjust better to their environment. We also offer provide training to parents of autistic individuals to become better guides and understand their child, and training and certification to professionals interested in becoming consultants in the field of learning disabilities.

 

Read More

BLOG

Insights on dealing with autism spectrum disorder as a family member, real-life success stories and latest news in the world about autism, all rolled into 1 place.

  •  
    40
    Shares
  • 13
  • 4
  • 3
  • 5
  • 15
  •