File: 20hooks.t

package info (click to toggle)
libclone-fast-perl 0.96-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 344 kB
  • sloc: perl: 200; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 654 bytes parent folder | download
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

use strict;
use warnings;

use Test::More qw( no_plan );
use Clone::Fast qw( clone );

use_ok( 'Clone::Fast' );

my $hooker = Hooker->new();
my $no_hooker = NoHooker->new();
ok( $hooker && $no_hooker );

ok( clone( $hooker ) );
ok( clone( $no_hooker ) );

ok( $hooker->is_ok() );
ok( ! $no_hooker->is_ok() );

package NoHooker;

{
	my $hooked;

	sub new { return bless {}, shift; }

	sub CLONEFAST_clone_x {
		$hooked++;
		return @_;
	}

	sub is_ok { return $hooked; }
}

package Hooker;

{
	my $hooked;

	sub new { return bless {}, shift; }

	sub CLONEFAST_clone {
		$hooked++;
		my ( $hook ) = @_;
		return $hook;
	}

	sub is_ok { return $hooked; }
}