summaryrefslogtreecommitdiff
path: root/ext/Attribute-Handlers/demo/Demo.pm
blob: e763d23b90e022d9616287ba36a252dcebb557a8 (plain)
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
$DB::single = 1;

package Demo;
$VERSION = '1.00';
use Attribute::Handlers;
no warnings 'redefine';

sub Demo : ATTR(SCALAR) {
	my ($package, $symbol, $referent, $attr, $data, $phase) = @_;
	$data = '<undef>' unless defined $data;
	print STDERR 'Scalar $', *{$symbol}{NAME},
		     " ($referent) was ascribed ${attr}\n",
		     "with data ($data)\nin phase $phase\n";
};

sub This : ATTR(SCALAR) {
	print STDERR "This at ",
		     join(":", map { defined() ? $_ : "" } caller(1)),
		     "\n";
}

sub Demo : ATTR(HASH) {
	my ($package, $symbol, $referent, $attr, $data) = @_;
	$data = '<undef>' unless defined $data;
	print STDERR 'Hash %', *{$symbol}{NAME},
		     " ($referent) was ascribed ${attr} with data ($data)\n";
};

sub Demo : ATTR(CODE) {
	my ($package, $symbol, $referent, $attr, $data) = @_;
	$data = '<undef>' unless defined $data;
	print STDERR 'Sub &', *{$symbol}{NAME},
		     " ($referent) was ascribed ${attr} with data ($data)\n";
};

sub Multi : ATTR {
	my ($package, $symbol, $referent, $attr, $data) = @_;
	$data = '<undef>' unless defined $data;
	print STDERR ref($referent), ' ', *{$symbol}{NAME},
		     " ($referent) was ascribed ${attr} with data ($data)\n";
};

sub ExplMulti : ATTR(ANY) {
	my ($package, $symbol, $referent, $attr, $data) = @_;
	$data = '<undef>' unless defined $data;
	print STDERR ref($referent), ' ', *{$symbol}{NAME},
		     " ($referent) was ascribed ${attr} with data ($data)\n";
};

1;