File: extends-non-moo.t

package info (click to toggle)
libmoo-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 856 kB
  • ctags: 192
  • sloc: perl: 2,561; makefile: 6
file content (83 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download | duplicates (3)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use Moo::_strictures;
use Test::More;
use Test::Fatal;

{
    package NonMooClass;
    BEGIN { $INC{'NonMooClass.pm'} = __FILE__ }
    sub new {
        my ($proto, $args) = @_;
        bless $args, $proto;
    }

    sub to_app {
        (shift)->{app};
    }

    package NonMooClass::Child;
    BEGIN { $INC{'NonMooClass/Child.pm'} = __FILE__ }
    use base qw(NonMooClass);

    sub wrap {
        my($class, $app) = @_;
        $class->new({app => $app})
              ->to_app;
    }

    package NonMooClass::Child::MooExtend;
    use Moo;
    extends 'NonMooClass::Child';

    package NonMooClass::Child::MooExtendWithAttr;
    use Moo;
    extends 'NonMooClass::Child';
    has 'attr' => (is=>'ro');

    package NonMooClass::Child::MooExtendWithAttr::Extend;
    use Moo;
    extends 'NonMooClass::Child::MooExtendWithAttr';
    has 'attr2' => (is=>'ro');
}

ok my $app = 100,
  'prepared $app';

ok $app = NonMooClass::Child->wrap($app),
  '$app from $app';

is $app, 100,
  '$app still 100';

ok $app = NonMooClass::Child::MooExtend->wrap($app),
  '$app from $app';

is $app, 100,
  '$app still 100';

ok $app = NonMooClass::Child::MooExtendWithAttr->wrap($app),
  '$app from $app';

is $app, 100,
  '$app still 100';

ok $app = NonMooClass::Child::MooExtendWithAttr::Extend->wrap($app),
  '$app from $app';

is $app, 100,
  '$app still 100';

{
  package BadPrototype;
  BEGIN { $INC{'BadPrototype.pm'} = __FILE__ }
  sub new () { bless {}, shift }
}
{
  package ExtendBadPrototype;
  use Moo;
  ::is(::exception {
    extends 'BadPrototype';
    has attr1 => (is => 'ro');
  }, undef, 'extending class with prototype on new');
}

done_testing();