File: struct.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 (53 lines) | stat: -rw-r--r-- 803 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
49
50
51
52
53
#!/usr/local/bin/perl

package X;

BEGIN { unshift @INC, ( $0 =~ /\A(.*?)[\w\.]+\z/ )[0] }

use Test;

use Class::MakeMethods::Emulator::MethodMaker
  struct => [ qw / a b c d / ],
  struct => 'e';

sub new { bless {}, shift; }
my $o = new X;

TEST { 1 };

TEST { ! $o->a };
TEST { ! $o->b };
TEST { ! $o->c };
TEST { ! $o->d };
TEST { ! $o->e };

my @f;
TEST { @f = $o->struct_fields; print "@f\n"; };
TEST {
  $f[0] eq 'a' and 
  $f[1] eq 'b' and 
  $f[2] eq 'c' and 
  $f[3] eq 'd' and 
  $f[4] eq 'e'
};

TEST { $o->struct(0,1,2,3,4) };

my %h;
TEST { %h = $o->struct_dump };
TEST {
  $h{'a'} == 0 and 
  $h{'b'} == 1 and 
  $h{'c'} == 2 and 
  $h{'d'} == 3 and 
  $h{'e'} == 4
};

TEST { $o->a('foo') };
TEST { $o->a eq 'foo' };

TEST { ! defined $o->clear_a };
TEST { ! defined $o->a };

exit 0;