File: 02_auto_deref.t

package info (click to toggle)
libmoosex-clone-perl 0.05-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 112 kB
  • ctags: 24
  • sloc: perl: 347; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download
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
52
53
54
55
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 5;

{

    package Foo;
    use Moose;
    with 'MooseX::Clone';

    has 'arr_ref' => (
        isa     => 'ArrayRef',
        is      => 'ro',
        default => sub { [qw/foo bar baz/] },
        traits  => [qw/Clone/]
    );

    package Bar;
    use Moose;
    with 'MooseX::Clone';

    has 'arr_ref' => (
        isa        => 'ArrayRef',
        is         => 'ro',
        auto_deref => 1,
        default    => sub { [qw/foo bar baz/] },
        traits     => [qw/Clone/]
    );

    package Baz;
    use Moose;
    with 'MooseX::Clone';

    has 'arr_ref' => (
        isa        => 'ArrayRef',
        is         => 'ro',
        auto_deref => 1,
        default    => sub { [qw/foo bar/] },
        traits     => [qw/Clone/]
    );
}

eval { Foo->new->clone };
ok( !$@, 'cloning simple obj with a ArrayRef' );

my $clone = eval { Bar->new->clone };
ok( !$@, 'cloning simple obj with a ArrayRef (3 elements) and auto_deref' );
ok( $clone, "got a clone" );
is_deeply( eval { [ $clone->arr_ref ] }, [qw(foo bar baz)], "value cloned properly" );

eval { Bar->new->clone };
ok( !$@, 'cloning simple obj with a ArrayRef (2 elements) and auto_deref' );