From eeb792decae28e85e487ebeeb6d56f1994b56c62 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 21 Feb 2011 01:07:16 -0600 Subject: handle type checks and auto_deref on values returned from services --- t/31-auto-deref.t | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 t/31-auto-deref.t (limited to 't/31-auto-deref.t') diff --git a/t/31-auto-deref.t b/t/31-auto-deref.t new file mode 100644 index 0000000..c86fffd --- /dev/null +++ b/t/31-auto-deref.t @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package Foo; + use Moose; + use MooseX::Bread::Board; + + has foo => ( + is => 'ro', + isa => 'ArrayRef', + auto_deref => 1, + block => sub { ['foo', 'bar'] }, + ); + + has bar => ( + is => 'ro', + isa => 'HashRef', + auto_deref => 1, + block => sub { {'foo' => 'bar'} }, + ); +} + +{ + my $foo = Foo->new; + + is_deeply(scalar($foo->foo), ['foo', 'bar'], "scalar array"); + is_deeply([$foo->foo], ['foo', 'bar'], "list array"); + is_deeply(scalar($foo->bar), {'foo', 'bar'}, "scalar hash"); + is_deeply({$foo->foo}, {'foo', 'bar'}, "list hash"); +} + +{ + my $foo = Foo->new(foo => ['foo', 'bar'], bar => {'foo' => 'bar'}); + + is_deeply(scalar($foo->foo), ['foo', 'bar'], "scalar array"); + is_deeply([$foo->foo], ['foo', 'bar'], "list array"); + is_deeply(scalar($foo->bar), {'foo', 'bar'}, "scalar hash"); + is_deeply({$foo->foo}, {'foo', 'bar'}, "list hash"); +} + +done_testing; -- cgit v1.2.3-54-g00ecf