File: accessor-reader-writer.t

package info (click to toggle)
libmoo-perl 0.091011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 476 kB
  • sloc: perl: 1,688; makefile: 4; sh: 1
file content (43 lines) | stat: -rw-r--r-- 675 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
use strictures 1;
use Test::More;
use Test::Fatal;

my @result;

{
  package Foo;

  use Moo;

  has one => (
    is     => 'rw',
    reader => 'get_one',
    writer => 'set_one',
  );
}

{
  package Bar;

  use Moo;

  has two => (
    is     => 'rw',
    accessor => 'TWO',
  );
}

my $foo = Foo->new(one => 'lol');
my $bar = Bar->new(two => '...');

is( $foo->get_one, 'lol', 'reader works' );
$foo->set_one('rofl');
is( $foo->get_one, 'rofl', 'writer works' );

ok( exception { $foo->get_one('blah') }, 'reader dies on write' );

is( $bar->TWO, '...', 'accessor works for reading' );
$bar->TWO('!!!');
is( $bar->TWO, '!!!', 'accessor works for writing' );

done_testing;