File Coverage

blib/lib/Class/Accessor/Fast/XS.pm
Criterion Covered Total %
statement 38 38 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 11 11 100.0
pod 4 4 100.0
total 56 58 96.5


line stmt bran cond sub pod time code
1              
2             =head1 NAME
3              
4             Class::Accessor::Fast::XS - XS replacement for Class::Accessor::Fast
5              
6             =head1 OBSOLETE NOTE
7              
8             This module has been stated rudimentary in favor of
9             L, that implements the same API.
10             Steffen Mueller did a great job improving concept of XS
11             accessors in L framework and keep improving it
12             further.
13              
14             At this moment (Dec 2010) Class::XSAccesor::Compat generates 25%
15             faster accessors than this module and has some thread safety fixes.
16             There is no point in porting fixes or improvements from Steffen's
17             code as you can just change the name and switch over.
18              
19             =head1 DESCRIPTION
20              
21             This module is a XS based replacement for L.
22             Just replace Class::Accessor::Fast with Class::Accessor::Fast::XS and
23             it should just work.
24              
25             Read L and L for API docs and
26             usage.
27              
28             XS is about performance, but usually optimized accessors like
29             L and many other with similar optimizations
30             give you enough performance to make accessors NOT a bottleneck.
31             In a real applications switch from Class::Accessor::Fast to this
32             module can give you 1-5% boost.
33              
34             Want to compare performance of different solutions?
35             Use L, but do remember that these benchmarks
36             don't take into account various properties and advances of different
37             implementations.
38              
39             =cut
40              
41             package Class::Accessor::Fast::XS;
42              
43 4     4   31761 use strict;
  4         9  
  4         109  
44 4     4   19 use warnings;
  4         5  
  4         117  
45 4     4   28 use base qw(Class::Accessor::Fast);
  4         7  
  4         320  
46              
47             our $VERSION = '0.04';
48              
49 4     4   22 use XSLoader;
  4         5  
  4         492  
50             XSLoader::load( __PACKAGE__, $VERSION );
51              
52             sub new {
53 4         41 return bless
54             defined $_[1]
55 6 100 33 6 1 14983 ? {%{$_[1]}} # make a copy of $fields.
56             : {},
57             ref $_[0] || $_[0];
58             }
59              
60             sub make_ro_accessor {
61 8     8 1 1233 my($class, $field) = @_;
62              
63 8         16 my $sub = $class ."::__xs_ro_". $field;
64 8         78 xs_make_ro_accessor($sub, $field);
65              
66 4     4   17 no strict 'refs';
  4         4  
  4         322  
67 8         10 return \&{$sub};
  8         31  
68             }
69              
70             sub make_wo_accessor {
71 8     8 1 303 my($class, $field) = @_;
72              
73 8         15 my $sub = $class ."::__xs_wo_". $field;
74 8         66 xs_make_wo_accessor($sub, $field);
75              
76 4     4   16 no strict 'refs';
  4         6  
  4         290  
77 8         10 return \&{$sub};
  8         32  
78             }
79              
80             sub make_accessor {
81 11     11 1 2128 my($class, $field) = @_;
82              
83 11         15 my $sub = $class ."::__xs_". $field;
84 11         80 xs_make_accessor($sub, $field);
85              
86 4     4   17 no strict 'refs';
  4         6  
  4         192  
87 11         11 return \&{$sub};
  11         38  
88             }
89              
90             =head1 CREDITS
91              
92             This code is heavily based on Steffen Mueller's L.
93              
94             =head1 SEE ALSO
95              
96             There are enormous amount of different accessors generators with different
97             properties, behavior and performance, here is list of some:
98              
99             L, L, L, L,
100             L...
101              
102             =head1 AUTHOR
103              
104             Ruslan Zakirov ERuslan.Zakirov@gmail.comE
105              
106             =head1 LICENSE
107              
108             This library is free software; you can redistribute it and/or modify
109             it under the same terms as Perl itself.
110              
111             =cut
112              
113             1;