File: getset.t

package info (click to toggle)
libmoosex-emulate-class-accessor-fast-perl 0.009032-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: perl: 224; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 944 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
use strict;
use warnings;
use Test::More tests => 9;

require_ok("MooseX::Adopt::Class::Accessor::Fast");
{
  @Foo::ISA = qw(Class::Accessor::Fast);
  Foo->mk_accessors(qw( foo ));
  my $test = Foo->new({ foo => 49 });
  is( $test->get('foo'), 49, "get initial foo");
  $test->set('foo', 42);
  is($test->get('foo'), 42, "get new foo");
}

{
  @Bar::ISA = qw(Class::Accessor::Fast);
  my $get_ref = Bar->make_ro_accessor('read');
  my $set_ref = Bar->make_wo_accessor('write');
  my $getset_ref = Bar->make_accessor('read_write');

  ok(Bar->meta->has_attribute("read"),"has read");
  ok(Bar->meta->has_attribute("write"),"has write");
  ok(Bar->meta->has_attribute("read_write"),"has read_write");

  my $obj = Bar->new({read => 1, write => 2, read_write => 3});
  is($get_ref->($obj), 1, "read get works");
  is($getset_ref->($obj), 3, "read_write get works");
  $getset_ref->($obj,2);
  is($getset_ref->($obj), 2, "read_write set works");
}