<?xml version="1.0" encoding="windows-1252"?>
<node id="1000208" title="Re: Core module: Attribute::Handlers behaviour" created="2012-10-21 07:43:28" updated="2012-10-21 07:43:28">
<type id="11">
note</type>
<author id="1000094">
enigma</author>
<data>
<field name="doctext">
&lt;p&gt;Even I'm not getting, why it is not working for "Test 4" ...&lt;/p&gt;

&lt;p&gt;Module.pm&lt;/p&gt;
&lt;code&gt;package Module;

use strict;
use warnings;
use Attribute::Handlers;

#sub TRACE :ATTR(CODE) {			# Test 1
#sub TRACE :ATTR(CODE,INIT) {		# Test 2
#sub TRACE :ATTR(CODE,CHECK) {		# Test 3
sub TRACE :ATTR(CODE,BEGIN) {		# Test 4
    my ($pkg, $sym, $ref, $attr, $data, $phase, $file, $line) = @_;
    *{ $sym } = sub {
        warn "$file($line) called with [@_]\n";
        my( @rc )= &amp;$ref;
        warn "$file($line): returning [ @rc ]\n";
    }
}

sub new :TRACE{
    my $instance        = shift;
    my $class           = ref($instance) || $instance;
    my $self            = {};
    return bless($self, $class);
}

END { }

1;

__END__&lt;/code&gt;

&lt;p&gt;Test.pl&lt;/p&gt;
&lt;code&gt;
#!/usr/local/bin/perl

use strict;
use warnings;

my $module_to_load     = 'Module';
eval "use $module_to_load;";

# Create object
my $obj               = Module-&gt;new();

print "REF: " . ref($obj) ."\n";
&lt;/code&gt;
&lt;p&gt;
Results: 
Test 1: Code compiles and executes, but without ATTR support.
&lt;/p&gt;
&lt;p&gt;
Test 2: Code compiles and executes, but without ATTR support.&lt;/p&gt;
&lt;p&gt;
Test 3: Code compiles and executes, but without ATTR support.&lt;/p&gt;
&lt;p&gt;
Test 4: Code throws and error msg as - 
&lt;code&gt;Can't locate object method "new" via package "Module" at ./Test.pl line 10.&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt; perl version: This is perl, v5.8.5 built for i386-linux-thread-multi&lt;/p&gt;
&lt;p&gt; OS version: Linux &lt;host&gt; 2.6.9-67.EL #1 Wed Nov 7 13:41:13 EST 2007 i686 i686 i386 GNU/Linux&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</field>
<field name="root_node">
1000101</field>
<field name="parent_node">
1000101</field>
</data>
</node>
