COPYRIGHT000664001750001750 323013727156401 14734 0ustar00taitai000000000000Lexical-Accessor-0.013Format: 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: Changes META.json META.yml doap.ttl t/30shv.t Copyright: Copyright 2020 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: 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: INSTALL LICENSE Makefile.PL TODO examples/benchmark.pl Copyright: Unknown License: Unknown Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: README lib/Lexical/Accessor.pm Copyright: This software is copyright (c) 2013-2014, 2017 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/rt101024.t Copyright: This software is copyright (c) 2017 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: lib/Sub/Accessor/Small.pm Copyright: This software is copyright (c) 2013-2014, 2017, 2020 by 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 Files: dist.ini Copyright: Copyright 2013 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2020 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) 2020 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000664001750001750 15713727156401 14446 0ustar00taitai000000000000Lexical-Accessor-0.013Maintainer: - Toby Inkster (TOBYINK) Contributor: - Lukas Atkinson (AMON) Changes000664001750001750 433213727156401 14740 0ustar00taitai000000000000Lexical-Accessor-0.013Lexical-Accessor ================ Created: 2013-10-21 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.013 2020-09-12 [ Documentation ] - Sub::Accessor::Small is now documented, albeit only slightly. [ Other ] - Sub::Accessor::Small now passes defaults/builders to Sub::HandlesVia. This should allow delegated reset to work. 0.012 2020-02-14 - Make Hash::FieldHash a recommendation rather than a requirement; fall back to Hash::Util::FieldHash on Perl 5.10+ and Hash::Util::FieldHash::Compat on Perl 5.8. 0.011 2020-02-14 - Allow private attributes to have public accessor methods. (They could already have public methods delegated to them.) 0.010 2020-02-14 [ Documentation ] - Document that you can use non-lexical methods for delegations. (This has already worked for at least five years.) [ Other ] - Added: Sub::HandlesVia support. 0.009 2017-06-13 [ Bug Fixes ] - Fixes for defaults in accessors. Fixes RT#101024. - Make `has` return coderefs as documented. Lukas Atkinson++ [ Other ] - Updated: Support Sub::Util instead of Sub::Name (with Sub::Name as a fallback). 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 INSTALL000664001750001750 171613727156401 14501 0ustar00taitai000000000000Lexical-Accessor-0.013 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 LICENSE000664001750001750 4365513727156401 14505 0ustar00taitai000000000000Lexical-Accessor-0.013This software is copyright (c) 2020 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) 2020 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, Fifth Floor, Boston, MA 02110-1301 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) 2020 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 MANIFEST000664001750001750 45113727156401 14554 0ustar00taitai000000000000Lexical-Accessor-0.013COPYRIGHT 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/30shv.t t/90subclassing.t t/rt101024.t META.json000664001750001750 503013727156401 15062 0ustar00taitai000000000000Lexical-Accessor-0.013{ "abstract" : "true private attributes for Moose/Moo/Mouse", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 1, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010", "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" : { "Hash::FieldHash" : "0", "Sub::HandlesVia" : "0", "Sub::Name" : "0", "Type::Utils" : "0.026" }, "requires" : { "Eval::TypeTiny" : "0", "Exporter::Tiny" : "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.013" }, "Sub::Accessor::Small" : { "file" : "lib/Sub/Accessor/Small.pm", "version" : "0.013" } }, "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.013", "x_contributors" : [ "Lukas Atkinson (AMON) " ], "x_serialization_backend" : "JSON::PP version 2.27400_02" } META.yml000664001750001750 261213727156401 14715 0ustar00taitai000000000000Lexical-Accessor-0.013--- 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: 1 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010' 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.013' Sub::Accessor::Small: file: lib/Sub/Accessor/Small.pm version: '0.013' recommends: Hash::FieldHash: '0' Sub::HandlesVia: '0' Sub::Name: '0' Type::Utils: '0.026' requires: Eval::TypeTiny: '0' Exporter::Tiny: '0' perl: '5.008003' resources: 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.013' x_contributors: - 'Lukas Atkinson (AMON) ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Makefile.PL000664001750001750 1465413727156401 15447 0ustar00taitai000000000000Lexical-Accessor-0.013use 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" => 1, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010", "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 => { "Hash::FieldHash" => 0, "Sub::HandlesVia" => 0, "Sub::Name" => 0, "Type::Utils" => 0.026, }, requires => { "Eval::TypeTiny" => 0, "Exporter::Tiny" => 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.013 }, "Sub::Accessor::Small" => { file => "lib/Sub/Accessor/Small.pm", version => 0.013 }, }, "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.013, "x_contributors" => ["Lukas Atkinson (AMON) "], }; my %dynamic_config; do { if ($] < 5.010000) { $meta->{prereqs}{runtime}{requires}{'Hash::Util::FieldHash::Compat'} = 0; } }; 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); README000664001750001750 2174613727156401 14355 0ustar00taitai000000000000Lexical-Accessor-0.013NAME 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 cannot 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, ); They can also be method names as strings: my ($set_foo); lexical_has foo => ( reader => 'get_foo', writer => \$set_foo, ); This allows you to provide a partly public API for an attribute. `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 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 . 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, 2017 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. SIGNATURE000664001750001750 527013727156401 14733 0ustar00taitai000000000000Lexical-Accessor-0.013This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.83. 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 SHA256 70234d302c81659190cdd6ffd8143daaeb08f6a18f6a8fcfcadb7fec0b3cb8a6 COPYRIGHT SHA256 4527aade62ed0470467e684f0a33d6b067e6fef7be1e57ce23b7aedba2c23674 CREDITS SHA256 ab75a91f711e7ffbbe73dbd490017c57932692c718bcd69a3bd782551a983873 Changes SHA256 3d509c67486ebff7179c08aae7243d61ca8e2d6c0d78952990da5ea9679e4ca5 INSTALL SHA256 1fb7395e76eabf94c421912d7d0a4f7fa745d49e1acb76b222c21d605b66bd25 LICENSE SHA256 f6645b91bf995caa462b72eb0770d787ca88406c3b00b4482bc1fa13445bc073 MANIFEST SHA256 29fd7d474d691b3fd82e625e8f51828539bb3e75d4e267fcea47e9074a0ca19a META.json SHA256 14217f7382949f8c6970afb28efe7a4c2fd78cc3e67f3e1553248ab766f61400 META.yml SHA256 9eb16ba989cba27245c96f3eeccbe6be3f54f334af288b35ff1496895775ebce Makefile.PL SHA256 befd78093b153fc868a415f69aa5456d10493efa827c69871044a75dbd3cafef README SHA256 61246118d6e0a838643c46428e0d86997d27a488c1c8d8c9b82453987482f5c9 TODO SHA256 a2f6dc324b3150afbfe90066a7e90e8b78afbbde73ff0f5644a110da9430911f dist.ini SHA256 49ae3f60df4bd6e2104eca7fdaed8057d51c1a11e4ac7deb24b47e0d32ef42a6 doap.ttl SHA256 48a80a0906b89701d731598bfbf1d69edbf46be71d1cd259080f6498d9c765cd examples/benchmark.pl SHA256 b73ebfc4fc1e2620c90ce360a720910e4aaf446cb557f656c69c7f874228a757 lib/Lexical/Accessor.pm SHA256 a09c11c636b8cdaff8929f8da4154989de7595ef392219569e696c2d1aaca5e6 lib/Sub/Accessor/Small.pm SHA256 49255f4f126ea0e134f48e8dcd43512d7d0e425e61116728bad034aa293587d8 t/01basic.t SHA256 bb6d40d2af39b90f283359f937ca8636d9c84fc28486d9377f4c6e9050813857 t/02moose.t SHA256 0aefa75842b35de3d2f8cb1e45303b25f8b2eb4521ac701be49671685f826eab t/03mouse.t SHA256 c15f7253df0e631998d662973cf7bdbb871b86948243811049c1a84439d52ff3 t/04moo.t SHA256 93e282e2f0c729acb2268fc372144c149cb861c04d1a1996e2241b0dc7ae8df1 t/05classtiny.t SHA256 4241923715a209f8d882b4be9bd50c0f50e7e59def79fa63f5904c66e332093a t/30shv.t SHA256 f6cae80846139a9003ed7f3d712c442d2847e451d54841f46651dce6b8ad8490 t/90subclassing.t SHA256 a5cfbe0b776efab3769d177b49cb9a661296982e9f425ec8c53234bb18b45ba9 t/rt101024.t -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQRVJKj/4+s6z4WzNujOv4Eoaip9OQUCX1zdAQAKCRDOv4Eoaip9 OW/dAJ9AJzteS9qRlhoXG9P5asYPut4AYwCgs6LD9z2GMwKReWhmS3+wwj0eQEI= =wUHe -----END PGP SIGNATURE----- TODO000664001750001750 2713727156401 14072 0ustar00taitai000000000000Lexical-Accessor-0.013- better test coverage dist.ini000664001750001750 10213727156401 15060 0ustar00taitai000000000000Lexical-Accessor-0.013;;class='Dist::Inkt::Profile::TOBYINK' ;;name='Lexical-Accessor' doap.ttl000664001750001750 3106113727156401 15134 0ustar00taitai000000000000Lexical-Accessor-0.013@prefix dc: . @prefix doap: . @prefix doap-bugs: . @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 "Hash::FieldHash"^^doap-deps:CpanId ], [ doap-deps:on "Sub::HandlesVia"^^doap-deps:CpanId ], [ 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: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::Fatal"^^doap-deps:CpanId ], [ 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: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 doap:Version; dc:identifier "Lexical-Accessor-0.009"^^xsd:string; dc:issued "2017-06-13"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Support Sub::Util instead of Sub::Name (with Sub::Name as a fallback)."; ], [ a doap-changeset:Bugfix; rdfs:label "Fixes for defaults in accessors."; doap-changeset:fixes ; ], [ a doap-changeset:Bugfix; rdfs:label "Make `has` return coderefs as documented."; doap-changeset:blame ; rdfs:seeAlso ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.009"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-0.010"^^xsd:string; dc:issued "2020-02-14"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Sub::HandlesVia support."; ], [ a doap-changeset:Documentation; rdfs:label "Document that you can use non-lexical methods for delegations. (This has already worked for at least five years.)"; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.010"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-0.011"^^xsd:string; dc:issued "2020-02-14"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Allow private attributes to have public accessor methods. (They could already have public methods delegated to them.)"; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.011"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-0.012"^^xsd:string; dc:issued "2020-02-14"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Make Hash::FieldHash a recommendation rather than a requirement; fall back to Hash::Util::FieldHash on Perl 5.10+ and Hash::Util::FieldHash::Compat on Perl 5.8."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.012"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-0.013"^^xsd:string; dc:issued "2020-09-12"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Sub::Accessor::Small now passes defaults/builders to Sub::HandlesVia. This should allow delegated reset to work."; ], [ a doap-changeset:Documentation; rdfs:label "Sub::Accessor::Small is now documented, albeit only slightly."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.013"^^xsd:string. a foaf:Person; foaf:name "Lukas Atkinson"; foaf:nick "AMON"; foaf:page . a foaf:Person; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page . a doap-bugs:Issue; doap-bugs:id "101024"^^xsd:string; doap-bugs:page . benchmark.pl000664001750001750 402613727156401 17552 0ustar00taitai000000000000Lexical-Accessor-0.013/examplesuse 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.t000664001750001750 70713727156401 15301 0ustar00taitai000000000000Lexical-Accessor-0.013/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.t000664001750001750 567013727156401 15367 0ustar00taitai000000000000Lexical-Accessor-0.013/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); # *_rv is the return value my ($aaa, $aaa_rv); # rw my ($get_bbb, $get_bbb_rv); # ro my ($get_ccc, $get_ccc_rv, $set_ccc, $set_ccc_rv); # rwp my ($get_ddd, $get_ddd_rv); # lazy { 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 }, ); $aaa_rv = lexical_has aaa => ( is => 'rw', accessor => \$aaa, ); $get_bbb_rv = lexical_has bbb => ( is => 'ro', reader => \$get_bbb, ); ($get_ccc_rv, $set_ccc_rv) = lexical_has ccc => ( is => 'rwp', reader => \$get_ccc, writer => \$set_ccc, ); $get_ddd_rv = lexical_has ddd => ( is => 'lazy', reader => \$get_ddd, default => sub { 42 }, ); } 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'); is($aaa_rv, $aaa, 'correct accessor returned for is => rw'); is($get_bbb_rv, $get_bbb, 'correct getter returned for is => ro'); is($get_ccc_rv, $get_ccc, 'correct getter returned for is => rwp'); is($set_ccc_rv, $set_ccc, 'correct setter returned for is => rwp'); is($get_ddd_rv, $get_ddd, 'correct reader returned for is => lazy'); done_testing; 03mouse.t000664001750001750 566613727156401 15403 0ustar00taitai000000000000Lexical-Accessor-0.013/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); # *_rv is the return value my ($aaa, $aaa_rv); # rw my ($get_bbb, $get_bbb_rv); # ro my ($get_ccc, $get_ccc_rv, $set_ccc, $set_ccc_rv); # rwp my ($get_ddd, $get_ddd_rv); # lazy { 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 }, ); $aaa_rv = lexical_has aaa => ( is => 'rw', accessor => \$aaa, ); $get_bbb_rv = lexical_has bbb => ( is => 'ro', reader => \$get_bbb, ); ($get_ccc_rv, $set_ccc_rv) = lexical_has ccc => ( is => 'rwp', reader => \$get_ccc, writer => \$set_ccc, ); $get_ddd_rv = lexical_has ddd => ( is => 'lazy', reader => \$get_ddd, default => sub { 42 }, ); } 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'); is($aaa_rv, $aaa, 'correct accessor returned for is => rw'); is($get_bbb_rv, $get_bbb, 'correct getter returned for is => ro'); is($get_ccc_rv, $get_ccc, 'correct getter returned for is => rwp'); is($set_ccc_rv, $set_ccc, 'correct setter returned for is => rwp'); is($get_ddd_rv, $get_ddd, 'correct reader returned for is => lazy'); done_testing; 04moo.t000664001750001750 565513727156401 15044 0ustar00taitai000000000000Lexical-Accessor-0.013/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); # *_rv is the return value my ($aaa, $aaa_rv); # rw my ($get_bbb, $get_bbb_rv); # ro my ($get_ccc, $get_ccc_rv, $set_ccc, $set_ccc_rv); # rwp my ($get_ddd, $get_ddd_rv); # lazy { 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 }, ); $aaa_rv = lexical_has aaa => ( is => 'rw', accessor => \$aaa, ); $get_bbb_rv = lexical_has bbb => ( is => 'ro', reader => \$get_bbb, ); ($get_ccc_rv, $set_ccc_rv) = lexical_has ccc => ( is => 'rwp', reader => \$get_ccc, writer => \$set_ccc, ); $get_ddd_rv = lexical_has ddd => ( is => 'lazy', reader => \$get_ddd, default => sub { 42 }, ); } 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'); is($aaa_rv, $aaa, 'correct accessor returned for is => rw'); is($get_bbb_rv, $get_bbb, 'correct getter returned for is => ro'); is($get_ccc_rv, $get_ccc, 'correct getter returned for is => rwp'); is($set_ccc_rv, $set_ccc, 'correct setter returned for is => rwp'); is($get_ddd_rv, $get_ddd, 'correct reader returned for is => lazy'); done_testing; 05classtiny.t000664001750001750 571513727156401 16261 0ustar00taitai000000000000Lexical-Accessor-0.013/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); # *_rv is the return value my ($aaa, $aaa_rv); # rw my ($get_bbb, $get_bbb_rv); # ro my ($get_ccc, $get_ccc_rv, $set_ccc, $set_ccc_rv); # rwp my ($get_ddd, $get_ddd_rv); # lazy { 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 }, ); $aaa_rv = lexical_has aaa => ( is => 'rw', accessor => \$aaa, ); $get_bbb_rv = lexical_has bbb => ( is => 'ro', reader => \$get_bbb, ); ($get_ccc_rv, $set_ccc_rv) = lexical_has ccc => ( is => 'rwp', reader => \$get_ccc, writer => \$set_ccc, ); $get_ddd_rv = lexical_has ddd => ( is => 'lazy', reader => \$get_ddd, default => sub { 42 }, ); } 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'); is($aaa_rv, $aaa, 'correct accessor returned for is => rw'); is($get_bbb_rv, $get_bbb, 'correct getter returned for is => ro'); is($get_ccc_rv, $get_ccc, 'correct getter returned for is => rwp'); is($set_ccc_rv, $set_ccc, 'correct setter returned for is => rwp'); is($get_ddd_rv, $get_ddd, 'correct reader returned for is => lazy'); done_testing; 30shv.t000664001750001750 136413727156401 15042 0ustar00taitai000000000000Lexical-Accessor-0.013/tuse strict; use warnings; use Test::More; use Test::Fatal; use Test::Requires 'Sub::HandlesVia'; use Test::Requires 'Types::Standard'; my $accessor; my $popper; my $obj = do { package Local::Class; use Types::Standard 'ArrayRef'; use Lexical::Accessor 'lexical_has'; lexical_has attr => ( is => 'rw', isa => ArrayRef, accessor => \$accessor, handles_via => 'Array', handles => [ \$popper => 'pop', pusher => 'push', ], ); bless {}; }; my @nums = (1..10); $obj->$accessor(\@nums); is_deeply( $obj->$accessor, [1..10], ); $obj->pusher(11, 12, 49); is_deeply( $obj->$accessor, [1..12, 49], ); is( scalar($obj->$popper), 49, ); is_deeply( $obj->$accessor, [1..12], ); done_testing; 90subclassing.t000664001750001750 211713727156401 16562 0ustar00taitai000000000000Lexical-Accessor-0.013/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; rt101024.t000664001750001750 115313727156401 15170 0ustar00taitai000000000000Lexical-Accessor-0.013/t=pod =encoding utf-8 =head1 PURPOSE Test for RT#101024. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2017 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 AAA; sub new { bless {}, shift } use Lexical::Accessor; lexical_has attr => ( accessor => \my $attr, default => sub { 90 }, ); sub get { shift->$attr } }; is( AAA->new->get, 90 ); done_testing; Accessor.pm000664001750001750 2472513727156401 17724 0ustar00taitai000000000000Lexical-Accessor-0.013/lib/Lexicaluse 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.013'; 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"); } else { $me->{lazy} ||= 1 if $me->{default} || $me->{builder}; } # 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 cannot 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, ); They can also be method names as strings: my ($set_foo); lexical_has foo => ( reader => 'get_foo', writer => \$set_foo, ); This allows you to provide a partly public API for an attribute. =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 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 L: 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; } } =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, 2017 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.pm000664001750001750 4132613727156401 20140 0ustar00taitai000000000000Lexical-Accessor-0.013/lib/Sub/Accessoruse 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 Scalar::Util qw( blessed reftype ); BEGIN { *HAS_SUB_UTIL = eval { require Sub::Util } ? sub(){1} : sub(){0}; *HAS_SUB_NAME = !HAS_SUB_UTIL() && eval { require Sub::Name } ? sub(){1} : sub(){0}; }; BEGIN { *fieldhash = eval { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } || eval { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } || do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash } ;; }; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.013'; 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; }; HAS_SUB_UTIL ? ($code = Sub::Util::set_subname("$me\::has", $code)) : HAS_SUB_NAME ? ($code = Sub::Name::subname("$me\::has", $code)) : (); 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 $shv_data; if ($me->{traits} or $me->{handles_via}) { my $orig_handles = $me->{handles}; require Sub::HandlesVia::Toolkit::Plain; $shv_data = 'Sub::HandlesVia::Toolkit::Plain'->clean_spec( $me->{package}, $me->{slot}, +{%$me}, ); if ($shv_data) { my @default = ref($me->{default}) ? ( $me->{default} ) : length($me->{builder}) ? ( $me->{builder} ) : (); my $callbacks = 'Sub::HandlesVia::Toolkit::Plain'->make_callbacks( $me->{package}, [ $me->reader, $me->writer, @default ], ); require Sub::HandlesVia::Handler; $me->{handles} = $orig_handles; my @pairs = $me->expand_handles; while (@pairs) { my ($target, $method) = splice(@pairs, 0, 2); my $handler = 'Sub::HandlesVia::Handler'->lookup($method, $shv_data->{handles_via}); $me->install_coderef( $target, $handler->coderef( %$callbacks, target => $me->{package}, method_name => ref($target) ? '__ANON__' : $target, ), ); } } } if (!$shv_data) { my @pairs = $me->expand_handles; while (@pairs) { my ($target, $method) = splice(@pairs, 0, 2); $me->install_coderef($target, $me->handles($method)); } } } my @return = map $$_, $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"; HAS_SUB_UTIL ? ($coderef = Sub::Util::set_subname($name, $coderef)) : HAS_SUB_NAME ? ($coderef = Sub::Name::subname($name, $coderef)) : (); 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_UTIL or HAS_SUB_NAME or do { require Sub::Util }; 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->{lazy} and !$me->{trigger} and !$me->{weak_ref}) { return sprintf( '(@_ > 1) ? (%s) : %s', $me->inline_access_w( $me->inline_type_assertion('$_[1]') ), $me->inline_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_reader, ); } 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_reader, ); } 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 - small toolkit for generating getter/setter methods =head1 SYNOPSIS package MyClass; use Sub::Accessor::Small; use Types::Standard qw( Int ); sub new { my $class = shift; my $self = bless \$class, $class; my %args = @_ == 1 ? %{ $_[0] } : @_; # Simple way to initialize each attribute for my $key ( sort keys %args ) { $self->$key( $args{$key} ); } return $self; } 'Sub::Accessor::Small'->new( package => __PACKAGE__, name => "foo", is => "rw", isa => Int, )->install_accessors(); package main; my $obj = MyClass->new( foo => 42 ); =head1 DESCRIPTION This is a small toolkit for generating Moose-like attribute accessors. B<< It does not generate a constructor. >> It stores attribute values inside-out, but it is designed for Sub::Accessor::Small to be subclassed, making it easy to store attributes in other ways. =head1 BUGS Please report any bugs to L. =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2017, 2020 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.