Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Accessing a scalar value in another subroutine?

by LanX (Chancellor)
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;
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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2016-06-29 08:25 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (372 votes). Check out past polls.