File: moo-accessors.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 (61 lines) | stat: -rw-r--r-- 990 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
use Moo::_strictures;
use Test::More;
use Sub::Quote qw(quote_sub);

{
  package Foo;

  use Moo;

  has one => (is => 'ro');
  has two => (is => 'rw', init_arg => undef);
  has three => (is => 'ro', init_arg => 'THREE', required => 1);

  package Bar;

  use Moo::Role;

  has four => (is => 'ro');
  ::quote_sub 'Bar::quoted' => '1';

  package Baz;

  use Moo;

  extends 'Foo';

  with 'Bar';

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

my $foo = Foo->new(
  one => 1,
  THREE => 3
);

is_deeply(
  { %$foo }, { one => 1, three => 3 }, 'simple class ok'
);

my $baz = Baz->new(
  one => 1,
  THREE => 3,
  four => 4,
  five => 5,
);

is_deeply(
  { %$baz }, { one => 1, three => 3, four => 4, five => 5 },
  'subclass with role ok'
);

ok(eval { Foo->meta->make_immutable }, 'make_immutable returns true');
ok(!$INC{"Moose.pm"}, "Didn't load Moose");

$baz->quoted;

is +$baz->can('quoted'), Bar->can('quoted'),
  'accessor from role is undeferred in consuming class';

done_testing unless caller;