| 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<Class::XSAccesor::Compat>, that implements the same API. | ||||||||||||||||||||||||||||
| 10 | Steffen Mueller did a great job improving concept of XS | ||||||||||||||||||||||||||||
| 11 | accessors in L<Class::XSAccesor> 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<Class::Accessor::Fast>. | ||||||||||||||||||||||||||||
| 22 | Just replace Class::Accessor::Fast with Class::Accessor::Fast::XS and | ||||||||||||||||||||||||||||
| 23 | it should just work. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Read L<Class::Accessor::Fast> and L<Class::Accessor> for API docs and | ||||||||||||||||||||||||||||
| 26 | usage. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | XS is about performance, but usually optimized accessors like | ||||||||||||||||||||||||||||
| 29 | L<Class::Accessor::Fast> 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<App::Benchmark::Accessors>, 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 4 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 4 | XSLoader::load( __PACKAGE__, $VERSION ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | return bless | ||||||||||||||||||||||||||||
| 54 | defined $_[1] | ||||||||||||||||||||||||||||
| 55 | 6 | ▶ | ? {%{$_[1]}} # make a copy of $fields. | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 56 | : {}, | ||||||||||||||||||||||||||||
| 57 | ref $_[0] || $_[0]; | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 8 | ▶ | sub make_ro_accessor { | ||||||||||||||||||||||||||
|
Subroutine
make_ro_accessor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 8 | my($class, $field) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 8 | my $sub = $class ."::__xs_ro_". $field; | |||||||||||||||||||||||||||
| 64 | 8 | xs_make_ro_accessor($sub, $field); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 8 | return \&{$sub}; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 8 | ▶ | sub make_wo_accessor { | ||||||||||||||||||||||||||
|
Subroutine
make_wo_accessor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 8 | my($class, $field) = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 8 | my $sub = $class ."::__xs_wo_". $field; | |||||||||||||||||||||||||||
| 74 | 8 | xs_make_wo_accessor($sub, $field); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 8 | return \&{$sub}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 11 | ▶ | sub make_accessor { | ||||||||||||||||||||||||||
|
Subroutine
make_accessor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 11 | my($class, $field) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 11 | my $sub = $class ."::__xs_". $field; | |||||||||||||||||||||||||||
| 84 | 11 | xs_make_accessor($sub, $field); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 11 | return \&{$sub}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 CREDITS | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | This code is heavily based on Steffen Mueller's L<Class::XSAccessor>. | ||||||||||||||||||||||||||||
| 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<accessors>, L<Class::Accessor>, L<Class::MethodMaker>, L<Class::XSAccessor>, | ||||||||||||||||||||||||||||
| 100 | L<Object::Accessor>... | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Ruslan Zakirov E<lt>Ruslan.Zakirov@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 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 | 4 | 1; | |||||||||||||||||||||||||||