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

Re: Accessing a scalar value in another subroutine?

by LanX (Canon)
on Sep 24, 2012 at 09:50 UTC ( #995333=note: print w/ replies, xml ) Need Help??


in reply to Accessing a scalar value in another subroutine?

Here the solution from "Perl Hacks". It's freely downloadable from O'Reilly

package Attribute::Docstring; use strict; use warnings; use Scalar::Util 'blessed'; use Attribute::Handlers; my %doc; sub UNIVERSAL::Doc :ATTR { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; return if $symbol eq 'LEXICAL'; my $name = *{$symbol}{NAME}; $doc{ $package }{$name} = $data; } sub UNIVERSAL::doc { my ($self, $name) = @_; my $package = blessed( $self ) || $self; return unless exists $doc{ $package }{ $name }; return $doc{ $package }{ $name }; } 1;
application
package Counter; use strict; use warnings; use Attribute::Docstring; our $counter :Doc( 'a count of all new Foo objects' ); sub new :Doc( 'the constructor for Foo' ) { $counter++; bless {}, shift; } sub get_count :Doc( 'returns the count for all foo objects' ) { return $counter; } 1;

Cheers Rolf


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://995333]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2014-09-18 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (119 votes), past polls