super_drone has asked for the wisdom of the Perl Monks concerning the following question:

Hello

Trying to learn/use subroutine attributes. However, can't seem to take very first steps :(

Following example code, gives an error:

Invalid CODE attribute: hold at ./attr.pl line 6

What am I doing wrong?

Thanks for you help.

where attr.pl is :

----------------------------- #!/usr/bin/perl package XYZ; use strict; sub abc :hold { } sub MODIFY_CODE_ATTRIBUTES { my ($pack,$ref,$attrs) = @_; (); } sub FETCH_CODE_ATTRIBUTES { return ('hold'); } 1; __END__

Replies are listed 'Best First'.
Re: learning subroutine attributes
by davorg (Chancellor) on Sep 20, 2006 at 14:03 UTC

    Your code is in the wrong order. You try to define the subroutine before you've defined the FETCH_CODE_ATTRIBUTES function. Therefore when Perl reaches the definition for 'abc', your attribute isn't defined.

    Try moving the definition of 'abc' to after the attribute functions.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: learning subroutine attributes
by adrianh (Chancellor) on Sep 20, 2006 at 17:14 UTC