File: 71_singleton.t

package info (click to toggle)
libaspect-perl 1.04-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: perl: 6,846; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 648 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 3;
use Test::NoWarnings;
use Aspect;

# Convert Foo into a singleton class
aspect Singleton => 'Foo::new';

my $foo1 = Foo->new;
my $foo2 = Foo->new;
is( "$foo1", "$foo2", 'there can only be one' );

# Create a lexical singleton to ensure it handles global vs lexical properly
SCOPE: {
	my $aspect = aspect Singleton => 'Bar::new';
	isa_ok( $aspect, 'Aspect::Library::Singleton' );
}





######################################################################
# Test Class

package Foo;

sub new {
	bless {}, shift;
};

package Bar;

sub new {
	bless {}, shift;
}