CONTRIBUTING 000644 001750 001750 5317 12315642762 15307 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 NAME
CONTRIBUTING
DESCRIPTION
If you're reading this document, that means you might be thinking about
helping me out with this project. Thanks!
Here's some ways you could help out:
* Bug reports
Found a bug? Great! (Well, not so great I suppose.)
The place to report them is . Don't e-mail me
about it, as your e-mail is more than likely to get lost amongst the
spam.
An example script clearly demonstrating the bug (preferably written
using Test::More) would be greatly appreciated.
* Patches
If you've found a bug and written a fix for it, even better!
Generally speaking you should check out the latest copy of the code
from the source repository rather than using the CPAN distribution.
The file META.yml should contain a link to the source repository. If
not, then try or submit a bug report.
(As far as I'm concerned the lack of a link is a bug.) Many of my
distributions are also mirrored at .
To submit the patch, do a pull request on GitHub or Bitbucket, or
attach a diff file to a bug report. Unless otherwise stated, I'll
assume that your contributions are licensed under the same terms as
the rest of the project.
(If using git, feel free to work in a branch. For Mercurial, I'd
prefer bookmarks within the default branch.)
* Documentation
If there's anything unclear in the documentation, please submit this
as a bug report or patch as above.
Non-toy example scripts that I can bundle would also be appreciated.
* Translation
Translations of documentation would be welcome.
For translations of error messages and other strings embedded in the
code, check with me first. Sometimes the English strings may not in
a stable state, so it would be a waste of time translating them.
Coding Style
I tend to write using something approximating the Allman style, using
tabs for indentation and Unix-style line breaks.
*
*
I nominally encode all source files as UTF-8, though in practice most of
them use a 7-bit-safe ASCII-compatible subset of UTF-8.
AUTHOR
Toby Inkster .
COPYRIGHT AND LICENCE
Copyright (c) 2012-2013 by Toby Inkster.
CONTRIBUTING.pod is licensed under the Creative Commons
Attribution-ShareAlike 2.0 UK: England & Wales License. To view a copy
of this license, visit
.
COPYRIGHT 000644 001750 001750 2466 12315642762 14752 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Lexical-Accessor
Upstream-Contact: Toby Inkster (TOBYINK)
Source: https://metacpan.org/release/Lexical-Accessor
Files: README
lib/Lexical/Accessor.pm
lib/Sub/Accessor/Small.pm
t/01basic.t
t/02moose.t
t/03mouse.t
t/04moo.t
t/05classtiny.t
Copyright: This software is copyright (c) 2013-2014 by Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: CONTRIBUTING
INSTALL
LICENSE
TODO
examples/benchmark.pl
Copyright: Unknown
License: Unknown
Files: Changes
META.json
META.yml
doap.ttl
Copyright: Copyright 2014 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: COPYRIGHT
CREDITS
SIGNATURE
Copyright: None
License: public-domain
Files: Makefile.PL
dist.ini
Copyright: Copyright 2013 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: t/90subclassing.t
Copyright: This software is copyright (c) 2014 by Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
License: Artistic-1.0
This software is Copyright (c) 2014 by the copyright holder(s).
This is free software, licensed under:
The Artistic License 1.0
License: GPL-1.0
This software is Copyright (c) 2014 by the copyright holder(s).
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
CREDITS 000644 001750 001750 71 12315642760 14423 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 Maintainer:
- Toby Inkster (TOBYINK)
Changes 000644 001750 001750 2150 12315642760 14736 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 Lexical-Accessor
================
Created: 2013-10-21
Home page:
Bug tracker:
Maintainer: Toby Inkster (TOBYINK)
0.008 2014-03-29
[ Bug Fixes ]
- Fix attribute defaults.
0.007 2014-03-29
- Much cleaned up Sub::Accessor::Small.
0.006 2014-03-29
- Split out the most reusable parts of Lexical::Accessor into
Sub::Accessor::Small.
0.005 2014-03-28
- Make Lexical::Accessor more even subclassable.
0.004 2014-03-28
- Make Lexical::Accessor more subclassable.
0.003 2013-12-15
- If Sub::Name is available, use it to name the exported `lexical_has`
keyword.
0.002 2013-10-22
[ Bug Fixes ]
- Fix is=>'lazy'.
[ Documentation ]
- Bundle a benchmarking script as an example.
- Comparisons with MooseX::Privacy, MooX::PrivateAttributes, etc.
- Fix minor (yet confusing) typo.
[ Other ]
- Default to is=>'rw' instead of is=>'bare'.
- Use Hash::FieldHash (it's significantly faster) instead of
Hash::Util::FieldHash::Compat.
0.001 2013-10-21 Initial release
INSTALL 000644 001750 001750 1716 12315642756 14510 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 Installing Lexical-Accessor should be straightforward.
INSTALLATION WITH CPANMINUS
If you have cpanm, you only need one line:
% cpanm Lexical::Accessor
If you are installing into a system-wide directory, you may need to pass
the "-S" flag to cpanm, which uses sudo to install the module:
% cpanm -S Lexical::Accessor
INSTALLATION WITH THE CPAN SHELL
Alternatively, if your CPAN shell is set up, you should just be able to
do:
% cpan Lexical::Accessor
MANUAL INSTALLATION
As a last resort, you can manually install it. Download the tarball and
unpack it.
Consult the file META.json for a list of pre-requisites. Install these
first.
To build Lexical-Accessor:
% perl Makefile.PL
% make && make test
Then install it:
% make install
If you are installing into a system-wide directory, you may need to run:
% sudo make install
LICENSE 000644 001750 001750 43653 12315642757 14513 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 This software is copyright (c) 2014 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.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 2014 by Toby Inkster.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Suite 500, Boston, MA 02110-1335 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 2014 by Toby Inkster.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. 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.
The End
MANIFEST 000644 001750 001750 437 12315642762 14564 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 CONTRIBUTING
COPYRIGHT
CREDITS
Changes
INSTALL
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
SIGNATURE
TODO
dist.ini
doap.ttl
examples/benchmark.pl
lib/Lexical/Accessor.pm
lib/Sub/Accessor/Small.pm
t/01basic.t
t/02moose.t
t/03mouse.t
t/04moo.t
t/05classtiny.t
t/90subclassing.t
META.json 000644 001750 001750 4551 12315642761 15074 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 {
"abstract" : "true private attributes for Moose/Moo/Mouse",
"author" : [
"Toby Inkster (TOBYINK) "
],
"dynamic_config" : 0,
"generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.015, CPAN::Meta::Converter version 2.120921",
"keywords" : [],
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Lexical-Accessor",
"no_index" : {
"directory" : [
"eg",
"examples",
"inc",
"t",
"xt"
]
},
"optional_features" : {},
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "6.17"
}
},
"develop" : {
"recommends" : {
"Dist::Inkt" : "0.001"
}
},
"runtime" : {
"recommends" : {
"Sub::Name" : "0",
"Type::Utils" : "0.026"
},
"requires" : {
"Eval::TypeTiny" : "0",
"Exporter::Tiny" : "0",
"Hash::FieldHash" : "0",
"perl" : "5.008003"
}
},
"test" : {
"recommends" : {
"Class::Tiny" : "0.006",
"Moo" : "1.000000",
"Moose" : "2.0000",
"Mouse" : "1.00"
},
"requires" : {
"Test::Fatal" : "0",
"Test::More" : "0.96",
"Test::Requires" : "0",
"Types::Standard" : "0.004"
}
}
},
"provides" : {
"Lexical::Accessor" : {
"file" : "lib/Lexical/Accessor.pm",
"version" : "0.008"
},
"Sub::Accessor::Small" : {
"file" : "lib/Sub/Accessor/Small.pm",
"version" : "0.008"
}
},
"release_status" : "stable",
"resources" : {
"X_identifier" : "http://purl.org/NET/cpan-uri/dist/Lexical-Accessor/project",
"bugtracker" : {
"web" : "http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor"
},
"homepage" : "https://metacpan.org/release/Lexical-Accessor",
"license" : [
"http://dev.perl.org/licenses/"
],
"repository" : {
"type" : "git",
"url" : "git://github.com/tobyink/p5-lexical-accessor.git",
"web" : "https://github.com/tobyink/p5-lexical-accessor"
}
},
"version" : "0.008"
}
META.yml 000644 001750 001750 2341 12315642761 14717 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 ---
abstract: 'true private attributes for Moose/Moo/Mouse'
author:
- 'Toby Inkster (TOBYINK) '
build_requires:
Test::Fatal: 0
Test::More: 0.96
Test::Requires: 0
Types::Standard: 0.004
configure_requires:
ExtUtils::MakeMaker: 6.17
dynamic_config: 0
generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.015, CPAN::Meta::Converter version 2.120921'
keywords: []
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Lexical-Accessor
no_index:
directory:
- eg
- examples
- inc
- t
- xt
optional_features: {}
provides:
Lexical::Accessor:
file: lib/Lexical/Accessor.pm
version: 0.008
Sub::Accessor::Small:
file: lib/Sub/Accessor/Small.pm
version: 0.008
recommends:
Sub::Name: 0
Type::Utils: 0.026
requires:
Eval::TypeTiny: 0
Exporter::Tiny: 0
Hash::FieldHash: 0
perl: 5.008003
resources:
X_identifier: http://purl.org/NET/cpan-uri/dist/Lexical-Accessor/project
bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor
homepage: https://metacpan.org/release/Lexical-Accessor
license: http://dev.perl.org/licenses/
repository: git://github.com/tobyink/p5-lexical-accessor.git
version: 0.008
Makefile.PL 000644 001750 001750 14335 12315642762 15447 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 use strict;
use ExtUtils::MakeMaker 6.17;
my $EUMM = eval( $ExtUtils::MakeMaker::VERSION );
my $meta = {
"abstract" => "true private attributes for Moose/Moo/Mouse",
"author" => ["Toby Inkster (TOBYINK) "],
"dynamic_config" => 0,
"generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.015, CPAN::Meta::Converter version 2.120921",
"keywords" => [],
"license" => ["perl_5"],
"meta-spec" => {
url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
version => 2,
},
"name" => "Lexical-Accessor",
"no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] },
"prereqs" => {
configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } },
develop => { recommends => { "Dist::Inkt" => 0.001 } },
runtime => {
recommends => { "Sub::Name" => 0, "Type::Utils" => 0.026 },
requires => {
"Eval::TypeTiny" => 0,
"Exporter::Tiny" => 0,
"Hash::FieldHash" => 0,
"perl" => 5.008003,
},
},
test => {
recommends => {
"Class::Tiny" => 0.006,
"Moo" => "1.000000",
"Moose" => "2.0000",
"Mouse" => "1.00",
},
requires => {
"Test::Fatal" => 0,
"Test::More" => 0.96,
"Test::Requires" => 0,
"Types::Standard" => 0.004,
},
},
},
"provides" => {
"Lexical::Accessor" => { file => "lib/Lexical/Accessor.pm", version => 0.008 },
"Sub::Accessor::Small" => { file => "lib/Sub/Accessor/Small.pm", version => 0.008 },
},
"release_status" => "stable",
"resources" => {
bugtracker => {
web => "http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor",
},
homepage => "https://metacpan.org/release/Lexical-Accessor",
license => ["http://dev.perl.org/licenses/"],
repository => {
type => "git",
url => "git://github.com/tobyink/p5-lexical-accessor.git",
web => "https://github.com/tobyink/p5-lexical-accessor",
},
X_identifier => "http://purl.org/NET/cpan-uri/dist/Lexical-Accessor/project",
},
"version" => 0.008,
};
my %dynamic_config;
my %WriteMakefileArgs = (
ABSTRACT => $meta->{abstract},
AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]),
DISTNAME => $meta->{name},
VERSION => $meta->{version},
EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ],
NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n },
test => { TESTS => "t/*.t" },
%dynamic_config,
);
$WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001;
sub deps
{
my %r;
for my $stage (@_)
{
for my $dep (keys %{$meta->{prereqs}{$stage}{requires}})
{
next if $dep eq 'perl';
my $ver = $meta->{prereqs}{$stage}{requires}{$dep};
$r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep};
}
}
\%r;
}
my ($build_requires, $configure_requires, $runtime_requires, $test_requires);
if ($EUMM >= 6.6303)
{
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{TEST_REQUIRES} ||= deps('test');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.5503)
{
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.52)
{
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test');
}
else
{
$WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime');
}
{
my ($minperl) = reverse sort(
grep defined && /^[0-9]+(\.[0-9]+)?$/,
map $meta->{prereqs}{$_}{requires}{perl},
qw( configure build runtime )
);
if (defined($minperl))
{
die "Installing $meta->{name} requires Perl >= $minperl"
unless $] >= $minperl;
$WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl
if $EUMM >= 6.48;
}
}
sub FixMakefile
{
return unless -d 'inc';
my $file = shift;
local *MAKEFILE;
open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out";
my $makefile = do { local $/; };
close MAKEFILE or die $!;
$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
$makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
$makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
$makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out";
print MAKEFILE $makefile or die $!;
close MAKEFILE or die $!;
}
my $mm = WriteMakefile(%WriteMakefileArgs);
FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile');
exit(0);
README 000644 001750 001750 17572 12315642756 14366 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 NAME
Lexical::Accessor - true private attributes for Moose/Moo/Mouse
SYNOPSIS
my $accessor = lexical_has identifier => (
is => 'rw',
isa => Int,
default => sub { 0 },
);
# or...
lexical_has identifier => (
is => 'rw',
isa => Int,
default => sub { 0 },
accessor => \$accessor,
);
# later...
say $self->$accessor; # says 0
$self->$accessor( 1 ); # setter
say $self->$accessor; # says 1
DESCRIPTION
Lexical::Accessor generates coderefs which can be used as methods to
access private attributes for objects.
The private attributes are stored inside-out, and do not add any accessors
to the class' namespace, so are completely invisible to any outside code,
including any subclasses. This gives your attribute complete privacy:
subclasses can define a private (or even public) attribute with the same
name as your private one and they will not interfere with each other.
Private attributes can not be initialized by Moose/Moo/Mouse constructors,
but you can safely initialize them inside a `BUILD` sub.
Functions
`lexical_has $name?, %options`
This module exports a function lexical_has which acts much like
Moose's `has` function, but sets up a private (lexical) attribute
instead of a public one.
Because lexical attributes are stored inside-out, the $name is
completely optional; however a name is recommended because it allows
better error messages to be generated.
The lexical_has function supports the following options:
`is`
Moose/Mouse/Moo-style `ro`, `rw`, `rwp` and `lazy` values are
supported. These control what sort of coderef is returned by the
`lexical_has` function itself.
my $reader = lexical_has "foo" => (is => "ro");
my $accessor = lexical_has "foo" => (is => "rw");
my ($reader, $writer) = lexical_has "foo" => (is => "rwp");
If generating more than one method it is probably clearer to pass
in scalar references to the `reader`, `writer`, etc methods,
rather than relying on the return value of the `lexical_has`
function.
`reader`, `writer`, `accessor`, `predicate`, `clearer`
These accept scalar references. The relevant coderefs will be
plonked into them:
my ($get_foo, $set_foo);
lexical_has foo => (
reader => \$get_foo,
writer => \$set_foo,
);
`default`, `builder`, `lazy`
Lazy defaults and builders are allowed. Eager (non-lazy) defaults
and builders are currently disallowed. (Use a `BUILD` sub to set
private attribute values at object construction time.)
The default may be either a non-reference value, or a coderef
which will be called as a method to return the value.
Builders probably make less sense than defaults because they
require a method in the class' namespace. The builder may be a
method name, or the special value '1' which will be interpreted as
meaning the attribute name prefixed by "_build_". If a coderef is
provided, this is automatically installed into the class'
namespace with the "_build_" prefix. (This last feature requires
Sub::Name.)
`isa`
A type constraint for the attribute. Moo-style coderefs are
accepted (including those generated by MooX::Types::MooseLike), as
are Moose::Meta::TypeConstraint/MooseX::Types objects, and
Mouse::Meta::TypeConstraint/MouseX::Types objects, and of course
Type::Tiny type constraints.
String type constraints may also be accepted, but only if
Type::Utils is installed. (String type constraints are reified
using `dwim_type`.)
`does`
As an alternative to `isa`, you can provide a role name in the
`does` option.
`coerce`
A coderef or Type::Coercion object is accepted.
If the special value '1' is provided, the type constraint object
is consulted to find the coercion. (This doesn't work for coderef
type constraints.)
`trigger`
A method name or coderef to trigger when a new value is set.
`auto_deref`
Boolean indicating whether to automatically dereference array and
hash values if called in list context.
`init_arg`
Must be `undef` if provided at all.
`required`
Must be false if provided at all.
`weak_ref`
Boolean. Makes the setter weaken any references it is called with.
`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 each pair is a scalar ref followed by a method name, a
coderef, or an arrayref (where the first element is a method name
or coderef and subsequent elements are curried arguments).
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/');
`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
.
SUPPORT
IRC: support is available through in the *#moops* channel on irc.perl.org
.
SEE ALSO
MooX::PrivateAttributes, MooX::ProtectedAttributes, MooseX::Privacy,
Sub::Private, Method::Lexical, etc...
AUTHOR
Toby Inkster .
COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
SIGNATURE 000644 001750 001750 4023 12315642762 14732 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.70.
To verify the content in this distribution, first make sure you have
Module::Signature installed, then type:
% cpansign -v
It will check each file's integrity, as well as the signature's
validity. If "==> Signature verified OK! <==" is not displayed,
the distribution may already have been compromised, and you should
not run its Makefile.PL or Build.PL.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
SHA1 294505f858f11dd062e9916e3f50d88210a9ef54 CONTRIBUTING
SHA1 bade81e5ce3021a6be79db2a0c87860b10cd9c71 COPYRIGHT
SHA1 6bd7b17d81be63d08d4efa6cb80106e72887842c CREDITS
SHA1 8f9530a191a853ad21081c81b1704cbe3da220d2 Changes
SHA1 65d83a565e9531b5c60250acf9166f190d25755f INSTALL
SHA1 47870123f373f5185d6893cb98bf06a8a05510aa LICENSE
SHA1 98f7424e6fabe0ba3d89b208589cdbc66b5b9992 MANIFEST
SHA1 47905f269daf1a1b50cfcdf7cd38e82a31ac434b META.json
SHA1 8e8d5ac9bef5e053d85c0b9110ba9f4c9a60f094 META.yml
SHA1 8621977586dfbefbad811468a626a0aa3e582567 Makefile.PL
SHA1 2ce0537f7e98d6fbfc4edfd1a4993bb1eaebc0a1 README
SHA1 09157188f2d36c907691c22e0293df46d1c00e5d TODO
SHA1 e29875a6b0ead31dacc90c0b3d4732c4e120c226 dist.ini
SHA1 24d58f4a4348281a95f45ec3513cb0a55b5c7124 doap.ttl
SHA1 ba3a28d912a990a7f7069ed99956319c4809a672 examples/benchmark.pl
SHA1 261b0a6fb2f6a8d12662539670e2461e121c655e lib/Lexical/Accessor.pm
SHA1 a88b20c195fe672142a08b908ff1a135f57c11e5 lib/Sub/Accessor/Small.pm
SHA1 1ebd54b8dc0daf6d2a97de85d77290f1c0bfafb8 t/01basic.t
SHA1 a7c4106ec680c4fbc26de89fc21c182a3f5dc566 t/02moose.t
SHA1 8114c0f90273cce33710ad6c67c5c7b72962ae92 t/03mouse.t
SHA1 2394411963e40706ad62fce231d37c8a36b77890 t/04moo.t
SHA1 f269a5071da0cd110d3f447458ed6a5817a7d030 t/05classtiny.t
SHA1 004d04d71b8b1c6136905cfa2e000f343b0dc3ec t/90subclassing.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
iEYEARECAAYFAlM3RfIACgkQzr+BKGoqfTlarQCcDnwLGAg/fKTlBOR39IL3/I7u
5B8An225GywNJ47B18f38i7GKdrYh5B0
=rdo1
-----END PGP SIGNATURE-----
TODO 000644 001750 001750 27 12315642756 14101 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 - better test coverage
dist.ini 000644 001750 001750 102 12315642756 15067 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 ;;class='Dist::Inkt::Profile::TOBYINK'
;;name='Lexical-Accessor'
doap.ttl 000644 001750 001750 17772 12315642761 15154 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008 @prefix dc: .
@prefix doap: .
@prefix doap-changeset: .
@prefix doap-deps: .
@prefix foaf: .
@prefix rdfs: .
@prefix xsd: .
dc:title "the same terms as the perl 5 programming language system itself".
a doap:Project;
dc:contributor ;
doap-deps:develop-recommendation [ doap-deps:on "Dist::Inkt 0.001"^^doap-deps:CpanId ];
doap-deps:runtime-recommendation [ doap-deps:on "Type::Utils 0.026"^^doap-deps:CpanId ], [ doap-deps:on "Sub::Name"^^doap-deps:CpanId ];
doap-deps:runtime-requirement [ doap-deps:on "perl 5.008003"^^doap-deps:CpanId ], [ doap-deps:on "Eval::TypeTiny"^^doap-deps:CpanId ], [ doap-deps:on "Exporter::Tiny"^^doap-deps:CpanId ], [ doap-deps:on "Hash::FieldHash"^^doap-deps:CpanId ];
doap-deps:test-recommendation [ doap-deps:on "Moo 1.000000"^^doap-deps:CpanId ], [ doap-deps:on "Mouse 1.00"^^doap-deps:CpanId ], [ doap-deps:on "Moose 2.0000"^^doap-deps:CpanId ], [ doap-deps:on "Class::Tiny 0.006"^^doap-deps:CpanId ];
doap-deps:test-requirement [ doap-deps:on "Test::Requires"^^doap-deps:CpanId ], [ doap-deps:on "Test::More 0.96"^^doap-deps:CpanId ], [
doap-deps:on "Types::Standard 0.004"^^doap-deps:CpanId;
], [ doap-deps:on "Test::Fatal"^^doap-deps:CpanId ];
doap:bug-database ;
doap:created "2013-10-21"^^xsd:date;
doap:developer ;
doap:download-page ;
doap:homepage ;
doap:license ;
doap:maintainer ;
doap:name "Lexical-Accessor";
doap:programming-language "Perl";
doap:release , , , , , , , ;
doap:repository [
a doap:GitRepository;
doap:browse ;
];
doap:shortdesc "true private attributes for Moose/Moo/Mouse".
a doap:Version;
rdfs:label "Initial release";
dc:identifier "Lexical-Accessor-0.001"^^xsd:string;
dc:issued "2013-10-21"^^xsd:date;
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.001"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.002"^^xsd:string;
dc:issued "2013-10-22"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Documentation;
rdfs:label "Fix minor (yet confusing) typo.";
], [
a doap-changeset:Documentation;
rdfs:label "Comparisons with MooseX::Privacy, MooX::PrivateAttributes, etc.";
], [
a doap-changeset:Documentation;
rdfs:label "Bundle a benchmarking script as an example.";
], [
a doap-changeset:Change;
rdfs:label "Use Hash::FieldHash (it's significantly faster) instead of Hash::Util::FieldHash::Compat.";
], [
a doap-changeset:Change;
rdfs:label "Default to is=>'rw' instead of is=>'bare'.";
], [
a doap-changeset:Bugfix;
rdfs:label "Fix is=>'lazy'.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.002"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.003"^^xsd:string;
dc:issued "2013-12-15"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "If Sub::Name is available, use it to name the exported `lexical_has` keyword.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.003"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.004"^^xsd:string;
dc:issued "2014-03-28"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "Make Lexical::Accessor more subclassable.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.004"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.005"^^xsd:string;
dc:issued "2014-03-28"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "Make Lexical::Accessor more even subclassable.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.005"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.006"^^xsd:string;
dc:issued "2014-03-29"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "Split out the most reusable parts of Lexical::Accessor into Sub::Accessor::Small.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.006"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.007"^^xsd:string;
dc:issued "2014-03-29"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Change;
rdfs:label "Much cleaned up Sub::Accessor::Small.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.007"^^xsd:string.
a doap:Version;
dc:identifier "Lexical-Accessor-0.008"^^xsd:string;
dc:issued "2014-03-29"^^xsd:date;
doap-changeset:changeset [
doap-changeset:item [
a doap-changeset:Bugfix;
rdfs:label "Fix attribute defaults.";
];
];
doap-changeset:released-by ;
doap:file-release ;
doap:revision "0.008"^^xsd:string.
a foaf:Person;
foaf:mbox ;
foaf:name "Toby Inkster";
foaf:nick "TOBYINK";
foaf:page .
benchmark.pl 000644 001750 001750 4026 12315642756 17561 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/examples use v5.14;
use Benchmark qw( cmpthese );
package Using_LexicalAccessor {
use Moose;
use Types::Standard 'Int';
use Lexical::Accessor;
my $foo;
lexical_has foo => (
isa => Int,
accessor => \$foo,
);
sub go {
my $self = shift;
$self->$foo(0);
for (1..1000) {
$self->$foo( $self->$foo + 1 );
}
}
__PACKAGE__->meta->make_immutable;
}
package Using_PrivateAttributes {
use Moose;
use Types::Standard 'Int';
use MooX::PrivateAttributes;
private_has foo => (
isa => Int,
accessor => 'foo',
);
sub go {
my $self = shift;
$self->foo(0);
for (1..1000) {
$self->foo( $self->foo + 1 );
}
}
__PACKAGE__->meta->make_immutable;
}
package Using_Moose {
use Moose;
use Types::Standard 'Int';
has foo => (
isa => Int,
accessor => '_foo',
);
sub go {
my $self = shift;
$self->_foo(0);
for (1..1000) {
$self->_foo( $self->_foo + 1 );
}
}
__PACKAGE__->meta->make_immutable;
}
package Using_MooseXPrivacy {
use Moose;
use MooseX::Privacy;
use Types::Standard 'Int';
has foo => (
isa => Int,
accessor => 'foo',
traits => ['Private'],
);
sub go {
my $self = shift;
$self->foo(0);
for (1..1000) {
$self->foo( $self->foo + 1 );
}
}
__PACKAGE__->meta->make_immutable;
}
my @implementations = qw( LexicalAccessor PrivateAttributes Moose MooseXPrivacy );
my $horror = 0;
for (@implementations)
{
my $obj = "Using_$_"->new;
do { $horror++; say "Something went horribly wrong with $obj!" } if eval { $obj->foo; 1 };
}
exit(1) if $horror;
cmpthese(-3, +{
map { my $class = "Using_$_"; $_ => qq[ $class\->new->go ] } @implementations
});
__END__
Rate MooseXPrivacy PrivateAttributes LexicalAccessor Moose
MooseXPrivacy 4.47/s -- -86% -95% -95%
PrivateAttributes 31.4/s 601% -- -63% -63%
LexicalAccessor 85.1/s 1803% 171% -- -0%
Moose 85.4/s 1809% 172% 0% --
01basic.t 000644 001750 001750 707 12315642756 15310 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/t =pod
=encoding utf-8
=head1 PURPOSE
Test that Lexical::Accessor compiles.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=cut
use strict;
use warnings;
use Test::More;
use_ok('Lexical::Accessor');
done_testing;
02moose.t 000644 001750 001750 4074 12315642756 15373 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/t =pod
=encoding utf-8
=head1 PURPOSE
Test that Lexical::Accessor works with Moose.
=head1 DEPENDENCIES
Moose 2.0000; skipped otherwise.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=cut
use strict;
use warnings;
use Test::More 0.96;
use Test::Requires { 'Moose', '2.0000' };
use Test::Fatal;
my $trigger;
my ($ggg, $get_ggg, $set_ggg, $has_ggg, $clear_ggg);
{
package Goose;
use Moose;
use Types::Standard qw(Str ArrayRef);
use Lexical::Accessor;
lexical_has ggg => (
accessor => \$ggg,
reader => \$get_ggg,
writer => \$set_ggg,
predicate => \$has_ggg,
clearer => \$clear_ggg,
isa => Str->plus_coercions(ArrayRef, q[join('', @$_)]),
coerce => 1,
trigger => sub { ++$trigger },
);
}
my $g1 = Goose->new;
my $g2 = Goose->new;
ok(!$g1->$has_ggg, 'predicate');
ok(!$g2->$has_ggg, 'predicate');
$g1->$set_ggg([qw/ foo bar /]);
ok( $g1->$has_ggg, 'setter makes value visible to predicate');
ok(!$g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, undef, '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, undef, '... does not mix up objects');
$g2->$ggg('xyz', 'abc');
ok( $g1->$has_ggg, 'accessor called as setter makes value visible to predicate');
ok( $g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, 'xyz', '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, 'xyz', '... does not mix up objects');
$g1->$clear_ggg;
ok(!$g1->$has_ggg, 'clearer');
ok( $g2->$has_ggg, '... does not mix up objects');
undef($g1);
undef($g2);
is($trigger, 2, 'triggers work');
ok(!keys %Sub::Accessor::Small::FIELDS, 'no leaks');
done_testing;
03mouse.t 000644 001750 001750 4072 12315642756 15400 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/t =pod
=encoding utf-8
=head1 PURPOSE
Test that Lexical::Accessor works with Mouse.
=head1 DEPENDENCIES
Mouse 1.00; skipped otherwise.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=cut
use strict;
use warnings;
use Test::More 0.96;
use Test::Requires { 'Mouse', '1.00' };
use Test::Fatal;
my $trigger;
my ($ggg, $get_ggg, $set_ggg, $has_ggg, $clear_ggg);
{
package Grouse;
use Mouse;
use Types::Standard qw(Str ArrayRef);
use Lexical::Accessor;
lexical_has ggg => (
accessor => \$ggg,
reader => \$get_ggg,
writer => \$set_ggg,
predicate => \$has_ggg,
clearer => \$clear_ggg,
isa => Str->plus_coercions(ArrayRef, q[join('', @$_)]),
coerce => 1,
trigger => sub { ++$trigger },
);
}
my $g1 = Grouse->new;
my $g2 = Grouse->new;
ok(!$g1->$has_ggg, 'predicate');
ok(!$g2->$has_ggg, 'predicate');
$g1->$set_ggg([qw/ foo bar /]);
ok( $g1->$has_ggg, 'setter makes value visible to predicate');
ok(!$g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, undef, '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, undef, '... does not mix up objects');
$g2->$ggg('xyz', 'abc');
ok( $g1->$has_ggg, 'accessor called as setter makes value visible to predicate');
ok( $g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, 'xyz', '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, 'xyz', '... does not mix up objects');
$g1->$clear_ggg;
ok(!$g1->$has_ggg, 'clearer');
ok( $g2->$has_ggg, '... does not mix up objects');
undef($g1);
undef($g2);
is($trigger, 2, 'triggers work');
ok(!keys %Sub::Accessor::Small::FIELDS, 'no leaks');
done_testing;
04moo.t 000644 001750 001750 4061 12315642756 15041 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/t =pod
=encoding utf-8
=head1 PURPOSE
Test that Lexical::Accessor works with Moo.
=head1 DEPENDENCIES
Moo 1.000000; skipped otherwise.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=cut
use strict;
use warnings;
use Test::More 0.96;
use Test::Requires { 'Moo', '1.000000' };
use Test::Fatal;
my $trigger;
my ($ggg, $get_ggg, $set_ggg, $has_ggg, $clear_ggg);
{
package Goo;
use Moo;
use Types::Standard qw(Str ArrayRef);
use Lexical::Accessor;
lexical_has ggg => (
accessor => \$ggg,
reader => \$get_ggg,
writer => \$set_ggg,
predicate => \$has_ggg,
clearer => \$clear_ggg,
isa => Str->plus_coercions(ArrayRef, q[join('', @$_)]),
coerce => 1,
trigger => sub { ++$trigger },
);
}
my $g1 = Goo->new;
my $g2 = Goo->new;
ok(!$g1->$has_ggg, 'predicate');
ok(!$g2->$has_ggg, 'predicate');
$g1->$set_ggg([qw/ foo bar /]);
ok( $g1->$has_ggg, 'setter makes value visible to predicate');
ok(!$g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, undef, '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, undef, '... does not mix up objects');
$g2->$ggg('xyz', 'abc');
ok( $g1->$has_ggg, 'accessor called as setter makes value visible to predicate');
ok( $g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, 'xyz', '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, 'xyz', '... does not mix up objects');
$g1->$clear_ggg;
ok(!$g1->$has_ggg, 'clearer');
ok( $g2->$has_ggg, '... does not mix up objects');
undef($g1);
undef($g2);
is($trigger, 2, 'triggers work');
ok(!keys %Sub::Accessor::Small::FIELDS, 'no leaks');
done_testing;
05classtiny.t 000644 001750 001750 4121 12315642756 16256 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/t =pod
=encoding utf-8
=head1 PURPOSE
Test that Lexical::Accessor works with Class::Tiny.
=head1 DEPENDENCIES
Class::Tiny 0.006; skipped otherwise.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=cut
use strict;
use warnings;
use Test::More 0.96;
use Test::Requires { 'Class::Tiny', '0.006' };
use Test::Fatal;
my $trigger;
my ($ggg, $get_ggg, $set_ggg, $has_ggg, $clear_ggg);
{
package Grimy;
use Class::Tiny;
use Types::Standard qw(Str ArrayRef);
use Lexical::Accessor;
lexical_has ggg => (
accessor => \$ggg,
reader => \$get_ggg,
writer => \$set_ggg,
predicate => \$has_ggg,
clearer => \$clear_ggg,
isa => Str->plus_coercions(ArrayRef, q[join('', @$_)]),
coerce => 1,
trigger => sub { ++$trigger },
);
}
my $g1 = Grimy->new;
my $g2 = Grimy->new;
ok(!$g1->$has_ggg, 'predicate');
ok(!$g2->$has_ggg, 'predicate');
$g1->$set_ggg([qw/ foo bar /]);
ok( $g1->$has_ggg, 'setter makes value visible to predicate');
ok(!$g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, undef, '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, undef, '... does not mix up objects');
$g2->$ggg('xyz', 'abc');
ok( $g1->$has_ggg, 'accessor called as setter makes value visible to predicate');
ok( $g2->$has_ggg, '... does not mix up objects');
is($g1->$ggg, 'foobar', '... and visible to accessor called as getter');
is($g2->$ggg, 'xyz', '... does not mix up objects');
is($g1->$get_ggg, 'foobar', '... and visible to reader');
is($g2->$get_ggg, 'xyz', '... does not mix up objects');
$g1->$clear_ggg;
ok(!$g1->$has_ggg, 'clearer');
ok( $g2->$has_ggg, '... does not mix up objects');
undef($g1);
undef($g2);
is($trigger, 2, 'triggers work');
ok(!keys %Sub::Accessor::Small::FIELDS, 'no leaks');
done_testing;
90subclassing.t 000644 001750 001750 2117 12315642756 16571 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/t =pod
=encoding utf-8
=head1 PURPOSE
Test that Lexical::Accessor can be subclassed to enable other
interesting accessor generators to build upon it.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2014 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.
=cut
use strict;
use warnings;
use Test::More;
BEGIN {
package Local::MyAccessor;
use base qw(Sub::Accessor::Small);
our @EXPORT = qw( has );
$INC{'Local/MyAccessor.pm'} = __FILE__;
# Store in a hashref instead of inside-out.
sub inline_access {
my $me = shift;
sprintf(
q[ $_[0]{%s} ],
$me->{slot},
);
}
};
BEGIN {
package Local::MyClass;
use Local::MyAccessor;
sub new {
bless {}, shift;
}
has foo => (accessor => 'foo');
has bar => (accessor => 'bar');
};
my $obj = Local::MyClass->new;
$obj->foo(42);
$obj->bar(666);
is($obj->foo, 42);
is($obj->bar, 666);
is_deeply(
+{ %$obj },
+{ foo => 42, bar => 666 },
);
done_testing;
Accessor.pm 000644 001750 001750 23152 12315642756 17724 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/lib/Lexical use 5.008003;
use strict;
use warnings;
no warnings qw( void once uninitialized );
package Lexical::Accessor;
use Carp qw(croak);
use Sub::Accessor::Small ();
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.008';
our @EXPORT = qw/ lexical_has /;
our @ISA = qw/ Sub::Accessor::Small /;
sub _generate_lexical_has : method
{
my $me = shift;
my $code = $me->_generate_has(@_);
$code = Sub::Name::subname("$me\::lexical_has", $code)
if Sub::Accessor::Small::HAS_SUB_NAME;
return $code;
}
sub lexical_has : method
{
my $has = $_[0]->can('has');
goto $has;
}
sub inline_to_coderef : method
{
my $me = shift;
my ($method_type, $code) = @_;
my $coderef = $me->SUPER::inline_to_coderef(@_);
Sub::Accessor::Small::HAS_SUB_NAME && $me->{package} && defined($me->{slot})
? Sub::Name::subname("$me->{package}\::__LEXICAL__[$me->{slot}]", $coderef)
: $coderef
}
sub accessor_kind : method
{
return 'lexical';
}
sub canonicalize_is : method
{
my $me = shift;
if ($me->{is} eq 'rw')
{
$me->{accessor} = \(my $tmp)
if !exists($me->{accessor});
}
elsif ($me->{is} eq 'ro')
{
$me->{reader} = \(my $tmp)
if !exists($me->{reader});
}
elsif ($me->{is} eq 'rwp')
{
$me->{reader} = \(my $tmp1)
if !exists($me->{reader});
$me->{writer} = \(my $tmp2)
if !exists($me->{writer});
}
elsif ($me->{is} eq 'lazy')
{
$me->{reader} = \(my $tmp)
if !exists($me->{reader});
$me->{lazy} = 1
if !exists($me->{lazy});
$me->{builder} = 1
unless $me->{builder} || $me->{default};
}
}
sub canonicalize_opts : method
{
my $me = shift;
$me->SUPER::canonicalize_opts(@_);
if (defined $me->{init_arg})
{
croak("Invalid init_arg=>defined; private attributes cannot be initialized in the constructor");
}
if ($me->{required})
{
croak("Invalid required=>1; private attributes cannot be initialized in the constructor");
}
if (defined $me->{lazy} and not $me->{lazy})
{
croak("Invalid lazy=>0; private attributes cannot be eager");
}
for my $type (qw/ reader writer accessor clearer predicate /)
{
if (defined($me->{$type}) and not ref($me->{$type}) eq q(SCALAR))
{
croak("Expected $type to be a scalar ref; not '$me->{$type}'");
}
}
}
sub expand_handles
{
my $me = shift;
if (ref($me->{handles}) eq q(ARRAY))
{
return @{$me->{handles}};
}
croak "Expected delegations to be a reference to an array; got $me->{handles}";
}
1;
__END__
=pod
=encoding utf-8
=for stopwords benchmarking
=head1 NAME
Lexical::Accessor - true private attributes for Moose/Moo/Mouse
=head1 SYNOPSIS
my $accessor = lexical_has identifier => (
is => 'rw',
isa => Int,
default => sub { 0 },
);
# or...
lexical_has identifier => (
is => 'rw',
isa => Int,
default => sub { 0 },
accessor => \$accessor,
);
# later...
say $self->$accessor; # says 0
$self->$accessor( 1 ); # setter
say $self->$accessor; # says 1
=head1 DESCRIPTION
Lexical::Accessor generates coderefs which can be used as methods to
access private attributes for objects.
The private attributes are stored inside-out, and do not add any
accessors to the class' namespace, so are completely invisible to any
outside code, including any subclasses. This gives your attribute
complete privacy: subclasses can define a private (or even public)
attribute with the same name as your private one and they will not
interfere with each other.
Private attributes can not be initialized by L/L/L
constructors, but you can safely initialize them inside a C sub.
=head2 Functions
=over
=item C<< lexical_has $name?, %options >>
This module exports a function L which acts much like
Moose's C function, but sets up a private (lexical) attribute
instead of a public one.
Because lexical attributes are stored inside-out, the C<$name> is
completely optional; however a name is recommended because it allows
better error messages to be generated.
The L function supports the following options:
=over
=item C<< is >>
Moose/Mouse/Moo-style C, C, C and C values are
supported. These control what sort of coderef is returned by the
C function itself.
my $reader = lexical_has "foo" => (is => "ro");
my $accessor = lexical_has "foo" => (is => "rw");
my ($reader, $writer) = lexical_has "foo" => (is => "rwp");
If generating more than one method it is probably clearer to pass in
scalar references to the C, C, etc methods, rather than
relying on the return value of the C function.
=item C<< reader >>, C<< writer >>, C<< accessor >>, C<< predicate >>,
C<< clearer >>
These accept scalar references. The relevant coderefs will be plonked
into them:
my ($get_foo, $set_foo);
lexical_has foo => (
reader => \$get_foo,
writer => \$set_foo,
);
=item C<< default >>, C<< builder >>, C<< lazy >>
Lazy defaults and builders are allowed. Eager (non-lazy) defaults and
builders are currently disallowed. (Use a C sub to set private
attribute values at object construction time.)
The default may be either a non-reference value, or a coderef which
will be called as a method to return the value.
Builders probably make less sense than defaults because they require
a method in the class' namespace. The builder may be a method name, or
the special value C<< '1' >> which will be interpreted as meaning the
attribute name prefixed by "_build_". If a coderef is provided, this is
automatically installed into the class' namespace with the "_build_"
prefix. (This last feature requires L.)
=item C<< isa >>
A type constraint for the attribute. L-style coderefs are
accepted (including those generated by L),
as are L/L objects,
and L/L objects, and
of course L type constraints.
String type constraints may also be accepted, but only if
L is installed. (String type constraints are reified
using C.)
=item C<< does >>
As an alternative to C, you can provide a role name in the
C option.
=item C<< coerce >>
A coderef or L object is accepted.
If the special value C<< '1' >> is provided, the type constraint object
is consulted to find the coercion. (This doesn't work for coderef type
constraints.)
=item C<< trigger >>
A method name or coderef to trigger when a new value is set.
=item C<< auto_deref >>
Boolean indicating whether to automatically dereference array and hash
values if called in list context.
=item C<< init_arg >>
Must be C if provided at all.
=item C<< required >>
Must be false if provided at all.
=item C<< weak_ref >>
Boolean. Makes the setter weaken any references it is called with.
=item C<< 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 each
pair is a scalar ref followed by a method name, a coderef, or an
arrayref (where the first element is a method name or coderef and
subsequent elements are curried arguments).
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/');
=item C<< initializer >>, C<< traits >>, C<< lazy_build >>
Not currently implemented. Providing any of these options throws an
error.
=item C<< documentation >>, C<< definition_context >>
Don't do anything, but are allowed; effectively inline comments.
=back
=back
=head2 Class Methods
=over
=item C<< lexical_has >>
This function may also be called as a class method.
=back
=head2 Comparison (benchmarking, etc)
Lexical::Accessor is almost three times faster than
L, and almost twenty time faster than
L. I'd also argue that it's a more "correct"
implementation of private accessors as (short of performing impressive
L 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!),
L clearly offers much better method privacy. There
should be little performance hit from using lexical accessors compared
to normal L accessors. (However they are nowhere near the speed
of the XS-powered accessors that L I uses and L
I uses.)
See also: C<< examples/benchmark.pl >> bundled with this release.
=head1 BUGS
Please report any bugs to
L.
=head1 SUPPORT
B<< IRC: >> support is available through in the I<< #moops >> channel
on L.
=head1 SEE ALSO
L,
L,
L,
L,
L,
etc...
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=head1 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.
Small.pm 000644 001750 001750 34466 12315642756 20156 0 ustar 00tai tai 000000 000000 Lexical-Accessor-0.008/lib/Sub/Accessor use 5.008003;
use strict;
use warnings;
no warnings qw( void once uninitialized );
package Sub::Accessor::Small;
use Carp qw( carp croak );
use Eval::TypeTiny qw();
use Exporter::Tiny qw();
use Hash::FieldHash qw( fieldhash );
use Scalar::Util qw( blessed reftype );
BEGIN {
*HAS_SUB_NAME = eval { require Sub::Name } ? sub(){1} : sub(){0};
};
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.008';
our @ISA = qw/ Exporter::Tiny /;
fieldhash( our %FIELDS );
sub _generate_has : method
{
my $me = shift;
my (undef, undef, $export_opts) = @_;
my $code = sub
{
my $attr = $me->new_from_has($export_opts, @_);
$attr->install_accessors;
};
$code = Sub::Name::subname("$me\::has", $code) if HAS_SUB_NAME;
return $code;
}
{
my $uniq = 0;
sub new_from_has : method
{
my $me = shift;
my $export_opts = ref($_[0]) eq 'HASH' ? shift(@_) : {};
my ($name, %opts) = (@_%2) ? @_ : (undef, @_);
my $package;
$package = $export_opts->{into}
if defined($export_opts->{into}) && !ref($export_opts->{into});
$me->new(
slot => $name,
id => $uniq++,
_export => $export_opts,
($package ? (package => $package) : ()),
%opts,
);
}
}
sub has : method
{
my $me = shift;
my $attr = $me->new_from_has(@_);
$attr->install_accessors;
}
sub new : method
{
my $me = shift;
my (%opts) = @_;
my $self = bless(\%opts, $me);
$self->canonicalize_opts;
return $self;
}
sub install_accessors : method
{
my $me = shift;
for my $type (qw( accessor reader writer predicate clearer ))
{
next unless defined $me->{$type};
$me->install_coderef($me->{$type}, $me->$type);
}
if (defined $me->{handles})
{
my @pairs = $me->expand_handles;
while (@pairs)
{
my ($target, $method) = splice(@pairs, 0, 2);
$me->install_coderef($target, $me->handles($method));
}
}
my @return =
$me->{is} eq 'ro' ? ($me->{reader}) :
$me->{is} eq 'rw' ? ($me->{accessor}) :
$me->{is} eq 'rwp' ? ($me->{reader}, $me->{writer}) :
$me->{is} eq 'lazy' ? ($me->{reader}) :
();
wantarray ? @return : $return[0];
}
sub install_coderef
{
my $me = shift;
my ($target, $coderef) = @_;
return unless defined $target;
if (!ref $target and $target =~ /\A[^\W0-9]\w+\z/)
{
my $name = "$me->{package}\::$target";
$coderef = Sub::Name::subname($name, $coderef) if HAS_SUB_NAME;
no strict qw(refs);
*$name = $coderef;
return;
}
if (ref($target) eq q(SCALAR) and not defined $$target)
{
$$target = $coderef;
return;
}
if (!ref($target) and $target eq 1)
{
return;
}
croak "Expected installation target to be a reference to an undefined scalar; got $target";
}
sub expand_handles
{
my $me = shift;
if (ref($me->{handles}) eq q(ARRAY))
{
return map ($_=>$_), @{$me->{handles}};
}
elsif (ref($me->{handles}) eq q(HASH))
{
return %{$me->{handles}};
}
croak "Expected delegations to be a reference to an array or hash; got $me->{handles}";
}
{
my %one = (
accessor => [qw/ %s %s /],
reader => [qw/ get_%s _get%s /],
writer => [qw/ set_%s _set%s /],
predicate => [qw/ has_%s _has%s /],
clearer => [qw/ clear_%s _clear%s /],
trigger => [qw/ _trigger_%s _trigger_%s /],
builder => [qw/ _builder_%s _builder_%s /],
);
sub canonicalize_1 : method
{
my $me = shift;
my $is_private = ($me->{slot} =~ /\A_/) ? 1 : 0;
for my $type (keys %one)
{
next if !exists($me->{$type});
next if ref($me->{$type});
next if $me->{$type} ne 1;
croak("Cannot interpret $type=>1 because attribute has no name defined")
if !defined $me->{slot};
$me->{$type} = sprintf($one{$type}[$is_private], $me->{slot});
}
}
sub canonicalize_builder : method
{
my $me = shift;
my $name = $me->{slot};
if (ref $me->{builder} eq 'CODE')
{
HAS_SUB_NAME or do { require Sub::Name };
my $code = $me->{builder};
defined($name) && defined($me->{package})
or croak("Invalid builder; expected method name as string");
my $is_private = ($name =~ /\A_/) ? 1 : 0;
my $subname = sprintf($one{builder}[$is_private], $name);
my $fq_subname = "$me->{package}\::$name";
$me->_exporter_install_sub(
$subname,
{},
$me->{_export},
Sub::Name::subname($fq_subname, $code),
);
}
}
}
sub canonicalize_is : method
{
my $me = shift;
my $name = $me->{slot};
if ($me->{is} eq 'rw')
{
$me->{accessor} = $name
if !exists($me->{accessor}) and defined $name;
}
elsif ($me->{is} eq 'ro')
{
$me->{reader} = $name
if !exists($me->{reader}) and defined $name;
}
elsif ($me->{is} eq 'rwp')
{
$me->{reader} = $name
if !exists($me->{reader}) and defined $name;
$me->{writer} = "_set_$name"
if !exists($me->{writer}) and defined $name;
}
elsif ($me->{is} eq 'lazy')
{
$me->{reader} = $name
if !exists($me->{reader}) and defined $name;
$me->{lazy} = 1
if !exists($me->{lazy});
$me->{builder} = 1
unless $me->{builder} || $me->{default};
}
}
sub canonicalize_default : method
{
my $me = shift;
return unless exists $me->{default};
unless (ref $me->{default})
{
my $value = $me->{default};
$me->{default} = sub { $value };
}
croak("Invalid default; expected a CODE ref")
unless ref $me->{default} eq 'CODE';
}
sub canonicalize_isa : method
{
my $me = shift;
if (my $does = $me->{does})
{
$me->{isa} ||= sub { blessed($_[0]) && $_[0]->DOES($does) };
}
if (defined $me->{isa} and not ref $me->{isa})
{
my $type_name = $me->{isa};
eval { require Type::Utils }
or croak("Missing requirement; type constraint strings require Type::Utils");
$me->{isa} = $me->{package}
? Type::Utils::dwim_type($type_name, for => $me->{package})
: Type::Utils::dwim_type($type_name);
}
}
sub canonicalize_trigger : method
{
my $me = shift;
if (defined $me->{trigger} and not ref $me->{trigger})
{
my $method_name = $me->{trigger};
$me->{trigger} = sub { my $self = shift; $self->$method_name(@_) };
}
}
sub canonicalize_opts : method
{
my $me = shift;
croak("Initializers are not supported") if $me->{initializer};
croak("Traits are not supported") if $me->{traits};
croak("The lazy_build option is not supported") if $me->{lazy_build};
$me->canonicalize_1;
$me->canonicalize_is;
$me->canonicalize_isa;
$me->canonicalize_default;
$me->canonicalize_builder;
$me->canonicalize_trigger;
}
sub accessor_kind : method
{
return 'small';
}
sub inline_to_coderef : method
{
my $me = shift;
my ($method_type, $code) = @_;
my $kind = $me->accessor_kind;
my $src = sprintf(q[sub { %s }], $code);
my $desc = defined($me->{slot})
? sprintf('%s %s for %s', $kind, $method_type, $me->{slot})
: sprintf('%s %s', $kind, $method_type);
# warn "#### $desc\n$src\n";
return Eval::TypeTiny::eval_closure(
source => $src,
environment => $me->{inline_environment},
description => $desc,
);
}
sub clearer : method
{
my $me = shift;
$me->inline_to_coderef(
clearer => $me->inline_clearer,
);
}
sub inline_clearer : method
{
my $me = shift;
sprintf(
q[ delete(%s) ],
$me->inline_access,
);
}
sub inline_access : method
{
my $me = shift;
sprintf(
q[ $Sub::Accessor::Small::FIELDS{$_[0]}{%d} ],
$me->{id},
);
}
sub inline_access_w : method
{
my $me = shift;
my ($expr) = @_;
sprintf(
q[ %s = %s ],
$me->inline_access,
$expr,
);
}
sub predicate : method
{
my $me = shift;
$me->inline_to_coderef(
predicate => $me->inline_predicate,
);
}
sub inline_predicate : method
{
my $me = shift;
sprintf(
q[ exists(%s) ],
$me->inline_access,
);
}
sub handles : method
{
my $me = shift;
my ($method) = @_;
$me->inline_to_coderef(
'delegated method' => $me->inline_handles,
);
}
my $handler_uniq = 0;
sub inline_handles : method
{
my $me = shift;
my ($method) = @_;
my $get = $me->inline_access;
my $varname = sprintf('$handler_%d', ++$handler_uniq);
$me->{inline_environment}{$varname} = \($method);
my $death = 'Scalar::Util::blessed($h) or Carp::croak("Expected blessed object to delegate to; got $h")';
if (ref $method eq 'ARRAY')
{
return sprintf(
q[ %s; my $h = %s; %s; shift; my ($m, @a) = @%s; $h->$m(@a, @_) ],
$me->inline_default,
$get,
$death,
$varname,
);
}
else
{
return sprintf(
q[ %s; my $h = %s; %s; shift; $h->%s(@_) ],
$me->inline_default,
$get,
$death,
$varname,
);
}
}
sub inline_get : method
{
my $me = shift;
my $get = $me->inline_access;
if ($me->{auto_deref})
{
$get = sprintf(
q[ do { my $x = %s; wantarray ? (ref($x) eq 'ARRAY' ? @$x : ref($x) eq 'HASH' ? %$x : $x ) : $x } ],
$get,
);
}
return $get;
}
sub inline_default : method
{
my $me = shift;
if ($me->{lazy})
{
my $get = $me->inline_access;
if ($me->{default})
{
$me->{inline_environment}{'$default'} = \($me->{default});
return sprintf(
q[ %s unless %s; ],
$me->inline_access_w( q[$default->($_[0])] ),
$me->inline_predicate,
);
}
elsif (defined $me->{builder})
{
return sprintf(
q[ %s unless %s; ],
$me->inline_access_w( q($_[0]->) . $me->{builder} ),
$me->inline_predicate,
);
}
}
return '';
}
sub reader : method
{
my $me = shift;
$me->inline_to_coderef(
reader => $me->inline_reader,
);
}
sub inline_reader : method
{
my $me = shift;
join('',
$me->inline_default,
$me->inline_get,
);
}
sub writer : method
{
my $me = shift;
$me->inline_to_coderef(
writer => $me->inline_writer,
);
}
sub inline_writer : method
{
my $me = shift;
my $get = $me->inline_access;
my $coerce = $me->inline_type_coercion('$_[1]');
if ($coerce eq '$_[1]') # i.e. no coercion
{
if (!$me->{trigger} and !$me->{weak_ref})
{
return $me->inline_access_w(
$me->inline_type_assertion('$_[1]'),
);
}
return sprintf(
'%s; %s; %s; %s; %s',
$me->inline_type_assertion('$_[1]'),
$me->inline_trigger('$_[1]', $get),
$me->inline_access_w('$_[1]'),
$me->inline_weaken,
$me->inline_get,
);
}
sprintf(
'my $val = %s; %s; %s; %s; %s; $val',
$coerce,
$me->inline_type_assertion('$val'),
$me->inline_trigger('$val', $get),
$me->inline_access_w('$val'),
$me->inline_weaken,
);
}
sub accessor : method
{
my $me = shift;
$me->inline_to_coderef(
accessor => $me->inline_accessor,
);
}
sub inline_accessor : method
{
my $me = shift;
my $get = $me->inline_access;
my $coerce = $me->inline_type_coercion('$_[1]');
if ($coerce eq '$_[1]') # i.e. no coercion
{
if (!$me->{trigger} and !$me->{weak_ref})
{
return sprintf(
'(@_ > 1) ? (%s) : %s',
$me->inline_access_w( $me->inline_type_assertion('$_[1]') ),
$get,
);
}
return sprintf(
'if (@_ > 1) { %s; %s; %s; %s }; %s',
$me->inline_type_assertion('$_[1]'),
$me->inline_trigger('$_[1]', $get),
$me->inline_access_w('$_[1]'),
$me->inline_weaken,
$me->inline_get,
);
}
sprintf(
'if (@_ > 1) { my $val = %s; %s; %s; %s; %s }; %s',
$coerce,
$me->inline_type_assertion('$val'),
$me->inline_trigger('$val', $get),
$me->inline_access_w('$val'),
$me->inline_weaken,
$me->inline_get,
);
}
sub inline_type_coercion : method
{
my $me = shift;
my ($var) = @_;
my $coercion = $me->{coerce} or return $var;
unless (ref $coercion)
{
my $type = $me->{isa};
if (blessed($type) and $type->can('coercion'))
{
$coercion = $type->coercion;
}
elsif (blessed($type) and $type->can('coerce'))
{
$coercion = sub { $type->coerce(@_) };
}
else
{
croak("Invalid coerce; type constraint cannot be probed for coercion");
}
unless (ref $coercion)
{
carp("Invalid coerce; type constraint has no coercion");
return $var;
}
}
if ( blessed($coercion)
and $coercion->can('can_be_inlined')
and $coercion->can_be_inlined
and $coercion->can('inline_coercion') )
{
return $coercion->inline_coercion($var);
}
# Otherwise need to close over $coerce
$me->{inline_environment}{'$coercion'} = \$coercion;
if ( blessed($coercion)
and $coercion->can('coerce') )
{
return sprintf('$coercion->coerce(%s)', $var);
}
return sprintf('$coercion->(%s)', $var);
}
sub inline_type_assertion : method
{
my $me = shift;
my ($var) = @_;
my $type = $me->{isa} or return $var;
if ( blessed($type)
and $type->isa('Type::Tiny')
and $type->can_be_inlined )
{
my $ass = $type->inline_assert($var);
if ($ass =~ /\Ado \{(.+)\};\z/sm)
{
return "do { $1 }"; # i.e. drop trailing ";"
}
# otherwise protect expression from trailing ";"
return "do { $ass }"
}
# Otherwise need to close over $type
$me->{inline_environment}{'$type'} = \$type;
# non-Type::Tiny but still supports inlining
if ( blessed($type)
and $type->can('can_be_inlined')
and $type->can_be_inlined )
{
my $inliner = $type->can('inline_check') || $type->can('_inline_check');
if ($inliner)
{
return sprintf('do { %s } ? %s : Carp::croak($type->get_message(%s))', $type->$inliner($var), $var, $var);
}
}
if ( blessed($type)
and $type->can('check')
and $type->can('get_message') )
{
return sprintf('$type->check(%s) ? %s : Carp::croak($type->get_message(%s))', $var, $var, $var);
}
return sprintf('$type->(%s) ? %s : Carp::croak("Value %s failed type constraint check")', $var, $var, $var);
}
sub inline_weaken : method
{
my $me = shift;
return '' unless $me->{weak_ref};
sprintf(
q[ Scalar::Util::weaken(%s) if ref(%s) ],
$me->inline_access,
$me->inline_access,
);
}
sub inline_trigger : method
{
my $me = shift;
my ($new, $old) = @_;
my $trigger = $me->{trigger} or return '';
$me->{inline_environment}{'$trigger'} = \$trigger;
return sprintf('$trigger->($_[0], %s, %s)', $new, $old);
}
1;
__END__
=pod
=encoding utf-8
=for stopwords benchmarking
=head1 NAME
Sub::Accessor::Small - base class used by Lexical::Accessor
=head1 DESCRIPTION
Not documented yet.
=head1 BUGS
Please report any bugs to
L.
=head1 SUPPORT
Using this module directly is currently unsupported.
=head1 SEE ALSO
L.
=head1 AUTHOR
Toby Inkster Etobyink@cpan.orgE.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=head1 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.