operator. (See L.) The parameter list is passed as it was found, however, and not as per C. Some examples of syntactically valid attribute lists: switch(10,foo(7,3)) : expensive Ugly('\(") :Bad _5x5 lvalue method Some examples of syntactically invalid attribute lists (with annotation): switch(10,foo() # ()-string not balanced Ugly('(') # ()-string not balanced 5x5 # "5x5" not a valid identifier Y2::north # "Y2::north" not a simple identifier foo + bar # "+" neither a colon nor whitespace =head1 EXPORTS =head2 Default exports None. =head2 Available exports The routines C and C are exportable. =head2 Export tags defined The C<:ALL> tag will get all of the above exports. =head1 EXAMPLES Here are some samples of syntactically valid declarations, with annotation as to how they resolve internally into C invocations by perl. These examples are primarily useful to see how the "appropriate package" is found for the possible method lookups for package-defined attributes. =over 4 =item 1. Code: package Canine; package Dog; my Canine $spot : Watchful ; Effect: use attributes (); attributes::->import(Canine => \$spot, "Watchful"); =item 2. Code: package Felis; my $cat : Nervous; Effect: use attributes (); attributes::->import(Felis => \$cat, "Nervous"); =item 3. Code: package X; sub foo : lvalue ; Effect: use attributes X => \&foo, "lvalue"; =item 4. Code: package X; sub Y::x : lvalue { 1 } Effect: use attributes Y => \&Y::x, "lvalue"; =item 5. Code: package X; sub foo { 1 } package Y; BEGIN { *bar = \&X::foo; } package Z; sub Y::bar : lvalue ; Effect: use attributes X => \&X::foo, "lvalue"; =back This last example is purely for purposes of completeness. You should not be trying to mess with the attributes of something in a package that's not your own. =head1 MORE EXAMPLES =over 4 =item 1. sub MODIFY_CODE_ATTRIBUTES { my ($class,$code,@attrs) = @_; my $allowed = 'MyAttribute'; my @bad = grep { $_ ne $allowed } @attrs; return @bad; } sub foo : MyAttribute { print "foo\n"; } This example runs. At compile time C is called. In that subroutine, we check if any attribute is disallowed and we return a list of these "bad attributes". As we return an empty list, everything is fine. =item 2. sub MODIFY_CODE_ATTRIBUTES { my ($class,$code,@attrs) = @_; my $allowed = 'MyAttribute'; my @bad = grep{ $_ ne $allowed }@attrs; return @bad; } sub foo : MyAttribute Test { print "foo\n"; } This example is aborted at compile time as we use the attribute "Test" which isn't allowed. C returns a list that contains a single element ('Test'). =back =head1 SEE ALSO L and L for details on the basic declarations; L for details on the normal invocation mechanism. =cut
. Some examples of syntactically valid attribute lists: switch(10,foo(7,3)) : expensive Ugly('\(") :Bad _5x5 lvalue method Some examples of syntactically invalid attribute lists (with annotation): switch(10,foo() # ()-string not balanced Ugly('(') # ()-string not balanced 5x5 # "5x5" not a valid identifier Y2::north # "Y2::north" not a simple identifier foo + bar # "+" neither a colon nor whitespace =head1 EXPORTS =head2 Default exports None. =head2 Available exports The routines C and C are exportable. =head2 Export tags defined The C<:ALL> tag will get all of the above exports. =head1 EXAMPLES Here are some samples of syntactically valid declarations, with annotation as to how they resolve internally into C invocations by perl. These examples are primarily useful to see how the "appropriate package" is found for the possible method lookups for package-defined attributes. =over 4 =item 1. Code: package Canine; package Dog; my Canine $spot : Watchful ; Effect: use attributes (); attributes::->import(Canine => \$spot, "Watchful"); =item 2. Code: package Felis; my $cat : Nervous; Effect: use attributes (); attributes::->import(Felis => \$cat, "Nervous"); =item 3. Code: package X; sub foo : lvalue ; Effect: use attributes X => \&foo, "lvalue"; =item 4. Code: package X; sub Y::x : lvalue { 1 } Effect: use attributes Y => \&Y::x, "lvalue"; =item 5. Code: package X; sub foo { 1 } package Y; BEGIN { *bar = \&X::foo; } package Z; sub Y::bar : lvalue ; Effect: use attributes X => \&X::foo, "lvalue"; =back This last example is purely for purposes of completeness. You should not be trying to mess with the attributes of something in a package that's not your own. =head1 MORE EXAMPLES =over 4 =item 1. sub MODIFY_CODE_ATTRIBUTES { my ($class,$code,@attrs) = @_; my $allowed = 'MyAttribute'; my @bad = grep { $_ ne $allowed } @attrs; return @bad; } sub foo : MyAttribute { print "foo\n"; } This example runs. At compile time C is called. In that subroutine, we check if any attribute is disallowed and we return a list of these "bad attributes". As we return an empty list, everything is fine. =item 2. sub MODIFY_CODE_ATTRIBUTES { my ($class,$code,@attrs) = @_; my $allowed = 'MyAttribute'; my @bad = grep{ $_ ne $allowed }@attrs; return @bad; } sub foo : MyAttribute Test { print "foo\n"; } This example is aborted at compile time as we use the attribute "Test" which isn't allowed. C returns a list that contains a single element ('Test'). =back =head1 SEE ALSO L and L for details on the basic declarations; L for details on the normal invocation mechanism. =cut