File: hash_counter_closure.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 (38 lines) | stat: -rw-r--r-- 678 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
#!/usr/bin/perl

use Test;
BEGIN { plan tests => 11 }

package X;

use Class::MakeMethods::Template::Hash (
  new     => 'new',
  number  => [ 'c', { 'interface' => { 
    -base => 'counter', '*_incr_func' => '-self_closure incr'
  } } ],
);

package main;

ok( 1 ); #1

my $o = X->new();

my $single_incr = $o->c_incr_func();
my $double_incr = $o->c_incr_func(2);

ok( ref( $single_incr and $double_incr ) ); #2

ok( $o->c() == 0 ); #3
ok( $o->c(123) ); #4
ok( $o->c() == 123 ); #5

ok( &$single_incr() == 124 ); #6
ok( $o->c() == 124 ); #7
ok( &$single_incr() == 125 ); #8
ok( &$double_incr() == 127 ); #9
ok( &$double_incr() == 129 ); #10
ok( $o->c() == 129 ); #11

exit 0;