File: 010_extending_and_embedding_back_compat.t

package info (click to toggle)
libmoose-perl 1.09-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 1,472
  • sloc: perl: 25,387; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,017 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
56
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Exception;


BEGIN {
    package MyFramework::Base;
    use Moose;

    package MyFramework::Meta::Base;
    use Moose;

    extends 'Moose::Meta::Class';

    package MyFramework;
    use Moose;
    use Moose::Deprecated -api_version => '0.55';

    sub import {
        my $CALLER = caller();

        strict->import;
        warnings->import;

        return if $CALLER eq 'main';
        Moose::init_meta( $CALLER, 'MyFramework::Base', 'MyFramework::Meta::Base' );
        Moose->import({ into => $CALLER });

        return 1;
    }
}

{
    package MyClass;
    BEGIN { MyFramework->import }

    has 'foo' => (is => 'rw');
}

can_ok( 'MyClass', 'meta' );

isa_ok(MyClass->meta, 'MyFramework::Meta::Base');
isa_ok(MyClass->meta, 'Moose::Meta::Class');

my $obj = MyClass->new(foo => 10);
isa_ok($obj, 'MyClass');
isa_ok($obj, 'MyFramework::Base');
isa_ok($obj, 'Moose::Object');

is($obj->foo, 10, '... got the right value');

done_testing;