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/] [Fast.pm] - Blame information for rev 56

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 alirezamon
package Class::Accessor::Fast;
2
use base 'Class::Accessor';
3
use strict;
4
use B 'perlstring';
5
$Class::Accessor::Fast::VERSION = '0.51';
6
 
7
sub make_accessor {
8
    my ($class, $field) = @_;
9
 
10
    eval sprintf q{
11
        sub {
12
            return $_[0]{%s} if scalar(@_) == 1;
13
            return $_[0]{%s}  = scalar(@_) == 2 ? $_[1] : [@_[1..$#_]];
14
        }
15
    }, map { perlstring($_) } $field, $field;
16
}
17
 
18
sub make_ro_accessor {
19
    my($class, $field) = @_;
20
 
21
    eval sprintf q{
22
        sub {
23
            return $_[0]{%s} if @_ == 1;
24
            my $caller = caller;
25
            $_[0]->_croak(sprintf "'$caller' cannot alter the value of '%%s' on objects of class '%%s'", %s, %s);
26
        }
27
    }, map { perlstring($_) } $field, $field, $class;
28
}
29
 
30
sub make_wo_accessor {
31
    my($class, $field) = @_;
32
 
33
    eval sprintf q{
34
        sub {
35
            if (@_ == 1) {
36
                my $caller = caller;
37
                $_[0]->_croak(sprintf "'$caller' cannot access the value of '%%s' on objects of class '%%s'", %s, %s);
38
            }
39
            else {
40
                return $_[0]{%s} = $_[1] if @_ == 2;
41
                return (shift)->{%s} = \@_;
42
            }
43
        }
44
    }, map { perlstring($_) } $field, $class, $field, $field;
45
}
46
 
47
1;
48
 
49
__END__
50
 
51
=head1 NAME
52
 
53
Class::Accessor::Fast - Faster, but less expandable, accessors
54
 
55
=head1 SYNOPSIS
56
 
57
  package Foo;
58
  use base qw(Class::Accessor::Fast);
59
 
60
  # The rest is the same as Class::Accessor but without set() and get().
61
 
62
=head1 DESCRIPTION
63
 
64
This is a faster but less expandable version of Class::Accessor.
65
Class::Accessor's generated accessors require two method calls to accomplish
66
their task (one for the accessor, another for get() or set()).
67
Class::Accessor::Fast eliminates calling set()/get() and does the access itself,
68
resulting in a somewhat faster accessor.
69
 
70
The downside is that you can't easily alter the behavior of your
71
accessors, nor can your subclasses.  Of course, should you need this
72
later, you can always swap out Class::Accessor::Fast for
73
Class::Accessor.
74
 
75
Read the documentation for Class::Accessor for more info.
76
 
77
=head1 EFFICIENCY
78
 
79
L<Class::Accessor/EFFICIENCY> for an efficiency comparison.
80
 
81
=head1 AUTHORS
82
 
83
Copyright 2017 Marty Pauley <marty+perl@martian.org>
84
 
85
This program is free software; you can redistribute it and/or modify it under
86
the same terms as Perl itself.  That means either (a) the GNU General Public
87
License or (b) the Artistic License.
88
 
89
=head2 ORIGINAL AUTHOR
90
 
91
Michael G Schwern <schwern@pobox.com>
92
 
93
=head1 SEE ALSO
94
 
95
L<Class::Accessor>
96
 
97
=cut

powered by: WebSVN 2.1.0

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