File: 10hash_lvalue.t

package info (click to toggle)
libclass-xsaccessor-perl 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 520 kB
  • sloc: perl: 841; ansic: 359; makefile: 6
file content (48 lines) | stat: -rw-r--r-- 823 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::More tests => 11;
BEGIN { use_ok('Class::XSAccessor') };

package Foo;
use Class::XSAccessor
  lvalue_accessors => {
    "bar" => "bar2"
  };

package main;

BEGIN {pass();}

ok( Foo->can('bar') );

my $foo = bless  {bar2 => 'b'} => 'Foo';
my $x = $foo->bar();
ok($x eq 'b');
$foo->bar = "buz";
ok($x eq 'b');
ok($foo->bar() eq 'buz');

{ # SCOPE
  my $baz = bless  {} => 'Foo';
  eval {
    $baz->bar = 12;
  };
  ok(!$@, 'assignment to !exists hash element is okay');
  is($baz->bar, 12);
}

{ # SCOPE
  my $baz = bless {} => 'Foo';
  my $baz2 = bless {} => 'Foo';
  eval {
    $baz->bar = $baz2;
  };
  ok(!$@, 'assignment to !exists hash element is okay');
  eval {
    $baz->bar->bar = 12;
  };
  ok(!$@, 'assignment to !exists hash element is okay');
  is($baz->bar->bar, 12);
}