Lexical-Accessor
view release on metacpan or search on metacpan
`handles`
Delegates methods. Has slightly different syntax to Moose's option
of the same name - is required to be an arrayref of pairs such
that in each pair, the first is a scalar ref or a string method
name that will be handled, and the second is a coderef or string
method name that will do the handling. (The second can be an
arrayref in the case of currying.)
my ($get, $post);
lexical_has ua => (
isa => 'HTTP::Tiny',
default => sub { 'HTTP::Tiny'->new },
handles => [
\$get => 'get',
\$post => 'post',
],
);
# later...
my $response = $self->$get('http://example.net/');
Supports Sub::HandlesVia:
my $remove_task;
lexical_has tasks => (
isa => ArrayRef,
handles_via => 'Array',
handles => [
task_count => 'count',
add_task => 'push',
next_task => [ 'get', 0 ],
\$remove_task => 'unshift',
],
);
# later...
while ($self->task_count) {
my $task = $self->next_task;
my $success = $self->handle_task($task);
if ($success) {
$self->$remove_task;
}
}
`initializer`, `traits`, `lazy_build`
Not currently implemented. Providing any of these options throws
an error.
`documentation`, `definition_context`
Don't do anything, but are allowed; effectively inline comments.
Class Methods
`lexical_has`
This function may also be called as a class method.
Comparison (benchmarking, etc)
Lexical::Accessor is almost three times faster than
MooX::PrivateAttributes, and almost twenty time faster than
MooseX::Privacy. I'd also argue that it's a more "correct" implementation
of private accessors as (short of performing impressive PadWalker
manipulations), the accessors generated by this module are completely
invisible to subclasses, method dispatch, etc.
Compared to the usual Moose convention of using a leading underscore to
indicate a private method (which is a very loose convention; it is quite
common for subclasses to override such methods!), Lexical::Accessor
clearly offers much better method privacy. There should be little
performance hit from using lexical accessors compared to normal Moose
accessors. (However they are nowhere near the speed of the XS-powered
accessors that Moo *sometimes* uses and Mouse *usually* uses.)
See also: `examples/benchmark.pl` bundled with this release.
BUGS
Please report any bugs to
<http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor>.
SUPPORT
IRC: support is available through in the *#moops* channel on irc.perl.org
<http://www.irc.perl.org/channels.html>.
SEE ALSO
MooX::PrivateAttributes, MooX::ProtectedAttributes, MooseX::Privacy,
Sub::Private, Method::Lexical, etc...
AUTHOR
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014, 2017, 2025 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.
( run in 1.153 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )