Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Accessing a scalar value in another subroutine?

by james2vegas (Chaplain)
on Sep 24, 2012 at 07:48 UTC ( #995305=note: print w/ replies, xml ) Need Help??


in reply to Accessing a scalar value in another subroutine?

Perhaps something like this, using Attribute-Handlers and putting the attribute in UNIVERSAL, which would, obviously, be optional:

package DocString; use Attribute::Handlers; use Data::Dumper; no warnings 'redefine'; our $docstrings; # sub Doc :ATTR(CODE) { sub UNIVERSAL::Doc :ATTR(CODE) { my ($package, $symbol, $referent, $attr, $data, $phase, $filename, + $linenum) = @_; $docstrings->{ $package }{ *{$symbol}{NAME} } = "@$data"; } # you could also have a docstring function exported from this module t +hat, given a package # and a sub returns # $DocString::docstrings->{$pkg}{$sub}); 1;

which could be used like this:

package Forble; use strict; use warnings; use DocString; sub veeblefaz :Doc("This method does the 2nd kind of veeblefaz operati +on!") { # this can be called from elsewhere, with the appropriate package +and sub names print Dumper($DocString::docstrings->{+__PACKAGE__}{veeblefaz}); + } 1;


Comment on Re: Accessing a scalar value in another subroutine?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995305]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2015-07-29 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls