Class-Variable

 view release on metacpan or  search on metacpan

lib/Class/Variable.pm  view on Meta::CPAN

package Class::Variable;
use 5.008;
use strict; use warnings FATAL => 'all'; 
use Exporter 'import';
use Carp;
use Scalar::Util 'weaken';

our $VERSION = '1.002'; # <== update version in pod

our @EXPORT;

my $NS = {};

push @EXPORT, 'public';
sub public($;)
{

lib/Class/Variable.pm  view on Meta::CPAN

    {
        my $self = shift;
        if( 
            not exists $NS->{$self}
            or not defined $NS->{$self}->{' self'} 
        )
        {
            $NS->{$self} = {
                ' self' => $self
            };
            weaken $NS->{$self}->{' self'};
        }
        
        $NS->{$self}->{$name};
    };
}

sub get_protected_variable($$)
{
    my( $package, $name ) = @_;
    

lib/Class/Variable.pm  view on Meta::CPAN

    {
        my $self = shift;
        if( 
            not exists $NS->{$self}
            or not defined $NS->{$self}->{' self'} 
        )
        {
            $NS->{$self} = {
                ' self' => $self
            };
            weaken $NS->{$self}->{' self'};
        }
        
        croak sprintf(
            "Access violation: protected variable %s of %s available only to class or subclasses, but not %s."
            , $name || 'undefined'
            , $package || 'undefined'
            , caller()  || 'undefined' ) if not caller()->isa($package);
            
        $NS->{$self}->{$name};
    };

lib/Class/Variable.pm  view on Meta::CPAN

    {
        my $self = shift;
        if( 
            not exists $NS->{$self}
            or not defined $NS->{$self}->{' self'} 
        )
        {
            $NS->{$self} = {
                ' self' => $self
            };
            weaken $NS->{$self}->{' self'};
        }
        
        croak sprintf(
            "Access violation: private variable %s of %s available only to class itself, not %s."
            , $name || 'undefined'
            , $package || 'undefined'
            , caller()  || 'undefined' ) if caller() ne $package;
            
        $NS->{$self}->{$name};
    };



( run in 1.078 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )