Toby Inkster > MooseX-XSAccessor-0.007 > MooseX::XSAccessor

Download:
MooseX-XSAccessor-0.007.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.007   Source  

NAME ^

MooseX::XSAccessor - use Class::XSAccessor to speed up Moose accessors

SYNOPSIS ^

   package MyClass;
   
   use Moose;
   use MooseX::XSAccessor;
   
   has foo => (...);

DESCRIPTION ^

This module accelerates Moose-generated accessor, reader, writer and predicate methods using Class::XSAccessor. You get a speed-up for no extra effort. It is automatically applied to every attribute in the class.

The use of the following features of Moose attributes prevents a reader from being accelerated:

The use of the following features prevents a writer from being accelerated:

An rw accessor is effectively a reader and a writer glued together, so both of the above lists apply.

Predicates can always be accelerated, provided you're using Class::XSAccessor 1.17 or above.

Clearers can not be accelerated (as of current versions of Class::XSAccessor).

Functions

This module also provides one function, which is not exported so needs to be called by its full name.

MooseX::XSAccessor::is_xs($sub)

Returns a boolean indicating whether a sub is an XSUB.

$sub may be a coderef, Class::MOP::Method object, or a qualified sub name as a string (e.g. "MyClass::foo").

Chained accessors and writers

MooseX::XSAccessor can detect chained accessors and writers created using MooseX::Attribute::Chained, and can accelerate those too.

   package Local::Class;
   use Moose;
   use MooseX::XSAccessor;
   use MooseX::Attribute::Chained;
   
   has foo => (traits => ["Chained"], is => "rw");
   has bar => (traits => ["Chained"], is => "ro", writer => "_set_bar");
   has baz => (                       is => "rw");  # not chained
   
   my $obj = "Local::Class"->new;
   $obj->foo(1)->_set_bar(2);
   print $obj->dump;

Lvalue accessors

MooseX::XSAccessor will detect lvalue accessors created with MooseX::LvalueAttribute and, by default, skip accelerating them.

However, by setting $MooseX::XSAccessor::LVALUE to true (preferably using the local Perl keyword), you can force it to accelerate those too. This introduces a visible change in behaviour though. MooseX::LvalueAttribute accessors normally allow two patterns for setting the value:

   $obj->foo = 42;   # as an lvalue
   $obj->foo(42);    # as a method call

However, once accelerated, they may only be set as an lvalue. For this reason, setting $MooseX::XSAccessor::LVALUE to true is considered an experimental feature.

HINTS ^

CAVEATS ^

BUGS ^

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-XSAccessor.

SEE ALSO ^

MooseX::XSAccessor::Trait::Attribute.

Moose, Moo, Class::XSAccessor.

AUTHOR ^

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE ^

This software is copyright (c) 2013 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES ^

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

syntax highlighting: