File: inheritable_hook.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 (41 lines) | stat: -rw-r--r-- 924 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
#!/usr/bin/perl

use Test;
BEGIN { plan tests => 6 }

########################################################################

package MyObject;

use Class::MakeMethods::Composite::Inheritable (
  'Composite::Hash:new' => 'new',
  hook => [ 'foo' ],
);

########################################################################

package main;

ok( 1 );

ok( ! defined MyObject->foo() );

MyObject->foo( Class::MakeMethods::Composite::Inheritable->Hook( sub { 
    my $callee = shift;
    return "foo $callee";
} ) );
ok( MyObject->foo() eq "foo MyObject" );

ok( $obj_1 = MyObject->new() );
ok( $obj_1->foo() eq "foo $obj_1" );

$obj_1->foo( Class::MakeMethods::Composite::Inheritable->Hook( sub { 
    my $callee = shift;
    Class::MakeMethods::Composite->CurrentResults(
      map { tr[a-z][A-Z]; $_ } Class::MakeMethods::Composite->CurrentResults()
    );
    return;
} ) );
ok( $obj_1->foo() eq uc("foo $obj_1") );

1;