Class-Variable

 view release on metacpan or  search on metacpan

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    {
        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

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
    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

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
    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 0.359 second using v1.01-cache-2.11-cpan-bf8d7bb2d05 )