Subject: | Cannot use attributes for anonymous subroutines |
When using Sub::Documentation::Attributes with anonymous subroutine, an error is thrown:
Can't use string ("ANON") as a symbol ref while "strict refs" in use at .../Sub/Documentation/Attributes.pm line 23
Simple reproduce:
perl -MSub::Documentation::Attributes -e '$sub = sub :Purpose(foobar) { ... }'
My suggestion is to use the string representation of the anonymous subref as the name.
my $name = $symbol eq 'ANON' ? "$referent" : *{$symbol}{NAME};
add_documentation(
package => $package,
glob_type => ref($referent),
name => $name,
type => $type,
documentation => $data,
);
So the documentation is still searchable.