OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [Integration_test/] [synthetic_sim/] [perl_lib/] [Class/] [Accessor/] [Faster.pm] - Blame information for rev 56

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 alirezamon
package Class::Accessor::Faster;
2
use base 'Class::Accessor';
3
use strict;
4
use B 'perlstring';
5
$Class::Accessor::Faster::VERSION = '0.51';
6
 
7
my %slot;
8
sub _slot {
9
    my($class, $field) = @_;
10
    my $n = $slot{$class}->{$field};
11
    return $n if defined $n;
12
    $n = keys %{$slot{$class}};
13
    $slot{$class}->{$field} = $n;
14
    return $n;
15
}
16
 
17
sub new {
18
    my($proto, $fields) = @_;
19
    my($class) = ref $proto || $proto;
20
    my $self = bless [], $class;
21
 
22
    $fields = {} unless defined $fields;
23
    for my $k (keys %$fields) {
24
        my $n = $class->_slot($k);
25
        $self->[$n] = $fields->{$k};
26
    }
27
    return $self;
28
}
29
 
30
sub make_accessor {
31
    my($class, $field) = @_;
32
    my $n = $class->_slot($field);
33
    eval sprintf q{
34
        sub {
35
            return $_[0][%d] if scalar(@_) == 1;
36
            return $_[0][%d]  = scalar(@_) == 2 ? $_[1] : [@_[1..$#_]];
37
        }
38
    }, $n, $n;
39
}
40
 
41
sub make_ro_accessor {
42
    my($class, $field) = @_;
43
    my $n = $class->_slot($field);
44
    eval sprintf q{
45
        sub {
46
            return $_[0][%d] if @_ == 1;
47
            my $caller = caller;
48
            $_[0]->_croak(sprintf "'$caller' cannot alter the value of '%%s' on objects of class '%%s'", %s, %s);
49
        }
50
    }, $n, map(perlstring($_), $field, $class);
51
}
52
 
53
sub make_wo_accessor {
54
    my($class, $field) = @_;
55
    my $n = $class->_slot($field);
56
    eval sprintf q{
57
        sub {
58
            if (@_ == 1) {
59
                my $caller = caller;
60
                $_[0]->_croak(sprintf "'$caller' cannot access the value of '%%s' on objects of class '%%s'", %s, %s);
61
            }
62
            else {
63
                return $_[0][%d] = $_[1] if @_ == 2;
64
                return (shift)->[%d] = \@_;
65
            }
66
        }
67
    }, map(perlstring($_), $field, $class), $n, $n;
68
}
69
 
70
1;
71
 
72
__END__
73
 
74
=head1 NAME
75
 
76
Class::Accessor::Faster - Even faster, but less expandable, accessors
77
 
78
=head1 SYNOPSIS
79
 
80
  package Foo;
81
  use base qw(Class::Accessor::Faster);
82
 
83
=head1 DESCRIPTION
84
 
85
This is a faster but less expandable version of Class::Accessor::Fast.
86
 
87
Class::Accessor's generated accessors require two method calls to accomplish
88
their task (one for the accessor, another for get() or set()).
89
 
90
Class::Accessor::Fast eliminates calling set()/get() and does the access itself,
91
resulting in a somewhat faster accessor.
92
 
93
Class::Accessor::Faster uses an array reference underneath to be faster.
94
 
95
Read the documentation for Class::Accessor for more info.
96
 
97
=head1 AUTHORS
98
 
99
Copyright 2017 Marty Pauley <marty+perl@martian.org>
100
 
101
This program is free software; you can redistribute it and/or modify it under
102
the same terms as Perl itself.  That means either (a) the GNU General Public
103
License or (b) the Artistic License.
104
 
105
=head1 SEE ALSO
106
 
107
L<Class::Accessor>
108
 
109
=cut

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.