File: hash_array_lvalue.t

package info (click to toggle)
libclass-makemethods-perl 1.01-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,944 kB
  • sloc: perl: 10,495; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 735 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
#!/usr/bin/perl

use Test;
BEGIN {
  eval q{ local $SIG{__DIE__}; require 5.6; 1 };
  if ( $@ ) {
    plan tests => 1;
    print "Skipping test on this platform (lvalue requires 5.6.0 or later).\n";
    ok( 1 );
    exit 0;
  }
}
BEGIN { plan tests => 9 }

package X;

use Class::MakeMethods::Template::Hash (
  new => 'new',
  'array --get --lvalue' => 'foo'
);

package main;

my $o = X->new;

ok( 1 ); #1
ok( ! scalar @{$o->foo} ); #2
ok( $o->foo = (123, 456) ); #3

ok( scalar( @a = $o->foo ) ); #4
ok( scalar(@a) == 2 and $o->foo->[1] == 456 ); #5

ok( ! scalar( @a = $o->foo() = () ) ); #6
ok( ! scalar @{$o->foo} ); #7
ok( $o->foo() = ('b', 'c', 'd') ); #8
ok( scalar( @a = $o->foo) == 3 and $o->foo->[1] eq 'c' ); #9

exit 0;