summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cantrell <david@cantrell.org.uk>2012-02-26 16:13:18 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-02-26 16:13:41 -0800
commitf29a7c30d92b9e3714cce5604d86fb97c1b099e8 (patch)
tree051af931ac0939b0374dbe55581322375b485789
parentf828ccba708aa823170a00f5a5fb04a26c9283af (diff)
downloadperl-f29a7c30d92b9e3714cce5604d86fb97c1b099e8.tar.gz
doco improvement for attributes.pm
It seems that many people have trouble understanding how to add custom attributes to their subroutines. Here's a doc patch that will hopefully make things clearer:
-rw-r--r--ext/attributes/attributes.pm16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/attributes/attributes.pm b/ext/attributes/attributes.pm
index a883c04d9f..fdc61e8b83 100644
--- a/ext/attributes/attributes.pm
+++ b/ext/attributes/attributes.pm
@@ -313,6 +313,22 @@ declaration. In particular, this means that a subroutine reference will
probably be for an undefined subroutine, even if this declaration is
actually part of the definition.
+It is up to this method to store the list of attributes if they will be
+needed later, as well as checking for any errors. In this example there
+are no error conditions, so we just store:
+
+ my %attrs;
+ sub MODIFY_CODE_ATTRIBUTES {
+ my($package, $subref, @attrs) = @_;
+ $attrs{ refaddr $subref } = \@attrs;
+ return;
+ }
+ sub FETCH_CODE_ATTRIBUTES {
+ my($package, $subref) = @_;
+ my $attrs = $attrs{ refaddr $subref };
+ return $attrs ? @$attrs : ();
+ }
+
=back
Calling C<attributes::get()> from within the scope of a null package