COPYRIGHT000664001750001750 402415134726625 15161 0ustar00taitai000000000000Lexical-Accessor-1.001000Format: 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 lib/Sub/HandlesVia/Toolkit/SubAccessorSmall.pm Copyright: Copyright 2026 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, 2025 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: t/90subclassing.t Copyright: This software is copyright (c) 2014 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/20triggers.t Copyright: This software is copyright (c) 2025 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/91chain.t Copyright: This software is copyright (c) 2026 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, 2025 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 Files: t/30shv.t Copyright: Copyright 2022 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2026 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) 2026 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000664001750001750 15715134726625 14671 0ustar00taitai000000000000Lexical-Accessor-1.001000Maintainer: - Toby Inkster (TOBYINK) Contributor: - Lukas Atkinson (AMON) Changes000664001750001750 612115134726625 15161 0ustar00taitai000000000000Lexical-Accessor-1.001000Lexical-Accessor ================ Created: 2013-10-21 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 1.001000 2026-01-23 [ Bug Fixes ] - Avoid is=>rw or is=>ro overriding explicitly named accessors. [ Other ] - Added: Support chainable accessors/writers/clearers. 1.000003 2026-01-09 [ Bug Fixes ] - Fix for accessors which a method name which is only one character long. - Fix for canonicalizing builder=>CODEREF. - Fix for lazy defaults/builders running triggers (triggers shouldn't run for defaults and builders). 1.000002 2025-12-18 - Major improvements to trigger implementation. - Reduce chance of collisions in the names of closed over variables. 1.000001 2025-12-16 - Fix default builder name to match documentation. 1.000000 2025-12-12 - Various changes to Sub::Accessor::Small, mostly to generate more efficient code, especially delegations. 0.014 2022-06-16 - Updated: Cope with changes to Sub::HandlesVia API; try to stick more to the public API. 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 171615134726625 14724 0ustar00taitai000000000000Lexical-Accessor-1.001000 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 4642715134726625 14730 0ustar00taitai000000000000Lexical-Accessor-1.001000This software is copyright (c) 2026 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) 2026 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 Perl Artistic License 1.0 --- This software is Copyright (c) 2026 by Toby Inkster. This is free software, licensed under: The Perl 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 as specified below. "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 uunet.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) give non-standard executables non-standard names, and clearly document 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. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 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 whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MANIFEST000664001750001750 56315134726625 15003 0ustar00taitai000000000000Lexical-Accessor-1.001000COPYRIGHT 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 lib/Sub/HandlesVia/Toolkit/SubAccessorSmall.pm t/01basic.t t/02moose.t t/03mouse.t t/04moo.t t/05classtiny.t t/20triggers.t t/30shv.t t/90subclassing.t t/91chain.t t/rt101024.t META.json000664001750001750 540015134726625 15306 0ustar00taitai000000000000Lexical-Accessor-1.001000{ "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.025", "Sub::Util" : "1.40", "Type::Utils" : "0.026" }, "requires" : { "Eval::TypeTiny" : "0", "Exporter::Tiny" : "0", "perl" : "5.008003" }, "suggests" : { "Sub::Name" : "0" } }, "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" : "1.001000" }, "Sub::Accessor::Small" : { "file" : "lib/Sub/Accessor/Small.pm", "version" : "1.001000" }, "Sub::HandlesVia::Toolkit::SubAccessorSmall" : { "file" : "lib/Sub/HandlesVia/Toolkit/SubAccessorSmall.pm", "version" : "1.001000" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/tobyink/p5-lexical-accessor/issues" }, "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" : "1.001000", "x_contributors" : [ "Lukas Atkinson (AMON) " ], "x_serialization_backend" : "JSON::PP version 4.16" } META.yml000664001750001750 302315134726625 15135 0ustar00taitai000000000000Lexical-Accessor-1.001000--- 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: '1.001000' Sub::Accessor::Small: file: lib/Sub/Accessor/Small.pm version: '1.001000' Sub::HandlesVia::Toolkit::SubAccessorSmall: file: lib/Sub/HandlesVia/Toolkit/SubAccessorSmall.pm version: '1.001000' recommends: Hash::FieldHash: '0' Sub::HandlesVia: '0.025' Sub::Util: '1.40' 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: https://github.com/tobyink/p5-lexical-accessor/issues homepage: https://metacpan.org/release/Lexical-Accessor license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-lexical-accessor.git version: '1.001000' x_contributors: - 'Lukas Atkinson (AMON) ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Makefile.PL000664001750001750 1411315134726625 15660 0ustar00taitai000000000000Lexical-Accessor-1.001000use 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.025, "Sub::Util" => "1.40", "Type::Utils" => 0.026, }, requires => { "Eval::TypeTiny" => 0, "Exporter::Tiny" => 0, "perl" => 5.008003 }, suggests => { "Sub::Name" => 0 }, }, 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 => "1.001000" }, "Sub::Accessor::Small" => { file => "lib/Sub/Accessor/Small.pm", version => "1.001000" }, "Sub::HandlesVia::Toolkit::SubAccessorSmall" => { file => "lib/Sub/HandlesVia/Toolkit/SubAccessorSmall.pm", version => "1.001000", }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "https://github.com/tobyink/p5-lexical-accessor/issues" }, 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" => "1.001000", "x_contributors" => ["Lukas Atkinson (AMON) "], }; my %dynamic_config; do { if ($] < 5.010000) { $meta->{prereqs}{runtime}{requires}{'Hash::Util::FieldHash::Compat'} = 0; } if (eval { require Sub::HandlesVia; 1 }) { $meta->{prereqs}{runtime}{requires}{'Sub::HandlesVia'} = '0.025'; } }; 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; } } my $mm = WriteMakefile(%WriteMakefileArgs); exit(0); README000664001750001750 2314415134726625 14572 0ustar00taitai000000000000Lexical-Accessor-1.001000NAME 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. `chain` If set to true, then writer and clearer methods, plus accessor methods when setting a value, will return the original object as their return value. This makes it possible to do: my $result = $obj->$set_foo(1)->$set_bar(2)->some_method(); $obj->$clear_foo->$clear_bar; It is also possible to set `chain` to an arrayref of which kinds of accessors are expected to be chainable. For example: `chain => [ 'clearer', 'writer' ]`. Only 'clearer', 'writer', and 'accessor' are valid values in this arrayref. `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, 2025 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. DISCLAIMER OF WARRANTIES THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. SIGNATURE000664001750001750 573715134726625 15166 0ustar00taitai000000000000Lexical-Accessor-1.001000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.88. 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: RIPEMD160 SHA256 9745478ec5882656a831e61f5936f134338b12397d472384d7fc55d6e9ce0de2 COPYRIGHT SHA256 4527aade62ed0470467e684f0a33d6b067e6fef7be1e57ce23b7aedba2c23674 CREDITS SHA256 4b55592f12c3e2c6d79576f2228b24a411cbf320cd9c1955ae539e79ed714517 Changes SHA256 3d509c67486ebff7179c08aae7243d61ca8e2d6c0d78952990da5ea9679e4ca5 INSTALL SHA256 ca1cc40b3da7bebb1b0368764650ad38ac603b31a25fbc5b6f9fb217cc6fa1e8 LICENSE SHA256 5197b6fb24ed53ac097cdd29f60555d72bce5d73330b2e51b6d39057d95688cf MANIFEST SHA256 b632d4f55bdb3068daa4ca70938aa7d8d6e4d8ec0722637ded4f9d3318dc079b META.json SHA256 3e10adbec43baefcec09427c1f5b26573a59ed96d7321723fe1bbc2ee8efe7c5 META.yml SHA256 fb9374b47bd0a3fe512296520e7690313cef1753eb637075a84ea429d1ff37b0 Makefile.PL SHA256 de326c957cfb570b64d6d9f0c356dab5b5cb3b84d13eabf2a2eaaf59734583c5 README SHA256 61246118d6e0a838643c46428e0d86997d27a488c1c8d8c9b82453987482f5c9 TODO SHA256 a2f6dc324b3150afbfe90066a7e90e8b78afbbde73ff0f5644a110da9430911f dist.ini SHA256 e0da408df4a3f91dc0705a09dbab3720f4d5500a6806a49127db5df362c91a91 doap.ttl SHA256 48a80a0906b89701d731598bfbf1d69edbf46be71d1cd259080f6498d9c765cd examples/benchmark.pl SHA256 212cdec2e2d4fbff24a31b12206b13c2864214404876bf6a356e6f8d7058fa9b lib/Lexical/Accessor.pm SHA256 43d243be8236c387ca7550220ffae8f5eb9b6e4edd784ba85799fffbbb258207 lib/Sub/Accessor/Small.pm SHA256 c7f9bd93be6e81560c6c57cba43398ee2e1e9f75ade28c9c49e5c139041b2a3f lib/Sub/HandlesVia/Toolkit/SubAccessorSmall.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 24607f801dd98c002b9267696efca2307d65f68dae963f2e1daa2181161cd53c t/20triggers.t SHA256 4241923715a209f8d882b4be9bd50c0f50e7e59def79fa63f5904c66e332093a t/30shv.t SHA256 ce3bcfdb50c1a20982de1c21cabd5d59c2b4f6f9406a56d3c092a597fa7d4f76 t/90subclassing.t SHA256 52b061f4f9407c32153f7a05c8889b3416670f45639c2c1cbfd18d96db238b6a t/91chain.t SHA256 a5cfbe0b776efab3769d177b49cb9a661296982e9f425ec8c53234bb18b45ba9 t/rt101024.t -----BEGIN PGP SIGNATURE----- iF0EAREDAB0WIQRVJKj/4+s6z4WzNujOv4Eoaip9OQUCaXOtlQAKCRDOv4Eoaip9 OSE7AJ9H3utSmUdb1BnWKofHRsBIEJUpJQCggFi/xoY6HmVQvmlaTsM9tJYR3BI= =nCES -----END PGP SIGNATURE----- TODO000664001750001750 2715134726625 14315 0ustar00taitai000000000000Lexical-Accessor-1.001000- better test coverage dist.ini000664001750001750 10215134726625 15303 0ustar00taitai000000000000Lexical-Accessor-1.001000;;class='Dist::Inkt::Profile::TOBYINK' ;;name='Lexical-Accessor' doap.ttl000664001750001750 4204615134726625 15364 0ustar00taitai000000000000Lexical-Accessor-1.001000@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 0.025"^^doap-deps:CpanId; ], [ doap-deps:on "Type::Utils 0.026"^^doap-deps:CpanId ], [ doap-deps:on "Sub::Util 1.40"^^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:runtime-suggestion [ doap-deps:on "Sub::Name"^^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 "Types::Standard 0.004"^^doap-deps:CpanId; ], [ 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: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 doap:Version; dc:identifier "Lexical-Accessor-0.014"^^xsd:string; dc:issued "2022-06-16"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Cope with changes to Sub::HandlesVia API; try to stick more to the public API."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.014"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-1.000000"^^xsd:string; dc:issued "2025-12-12"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Various changes to Sub::Accessor::Small, mostly to generate more efficient code, especially delegations."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "1.000000"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-1.000001"^^xsd:string; dc:issued "2025-12-16"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Fix default builder name to match documentation."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "1.000001"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-1.000002"^^xsd:string; dc:issued "2025-12-18"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Major improvements to trigger implementation."; ], [ a doap-changeset:Change; rdfs:label "Reduce chance of collisions in the names of closed over variables."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "1.000002"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-1.000003"^^xsd:string; dc:issued "2026-01-09"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix for lazy defaults/builders running triggers (triggers shouldn't run for defaults and builders)."; ], [ a doap-changeset:Bugfix; rdfs:label "Fix for canonicalizing builder=>CODEREF."; ], [ a doap-changeset:Bugfix; rdfs:label "Fix for accessors which a method name which is only one character long."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "1.000003"^^xsd:string. a doap:Version; dc:identifier "Lexical-Accessor-1.001000"^^xsd:string; dc:issued "2026-01-23"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Support chainable accessors/writers/clearers."; ], [ a doap-changeset:Bugfix; rdfs:label "Avoid is=>rw or is=>ro overriding explicitly named accessors."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "1.001000"^^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 402615134726625 17775 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 70715134726625 15524 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 567015134726625 15612 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 566615134726625 15626 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 565515134726625 15267 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 571515134726625 16504 0ustar00taitai000000000000Lexical-Accessor-1.001000/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; 20triggers.t000664001750001750 315715134726625 16314 0ustar00taitai000000000000Lexical-Accessor-1.001000/t=pod =encoding utf-8 =head1 PURPOSE Test implementation of triggers. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2025 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =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; my $selfvar = shift || '$_[0]'; require B; sprintf( q[ %s->{%s} ], $selfvar, B::perlstring($me->{slot}), ); } }; my ( @FOO, @BAR ); BEGIN { package Local::MyClass; use Local::MyAccessor; sub new { my $class = shift; bless { @_ }, $class; } has foo => ( is => 'rw', trigger => sub { my ( $self, @args ) = @_; push @FOO, \@args; $self->foo( $args[0] + 1 ); }, ); has bar => ( is => 'rw', trigger => 'trigger_bar', ); sub trigger_bar { my ( $self, @args ) = @_; push @BAR, \@args; $self->bar( $args[0] + 1 ); } }; my $obj = Local::MyClass->new; $obj->foo( 1 ); is $obj->foo, 2; $obj->foo( 41 ); is $obj->foo, 42; $obj->bar( 1 ); is $obj->bar, 2; $obj->bar( 41 ); is $obj->bar, 42; is_deeply( $obj, bless( { foo => 42, bar => 42 }, 'Local::MyClass' ), ) or diag explain($obj); is_deeply( \@FOO, [ [ 1 ], [ 41, 2 ], ], ) or diag explain \@FOO; is_deeply( \@BAR, [ [ 1 ], [ 41, 2 ], ], ) or diag explain \@FOO; done_testing; 30shv.t000664001750001750 136415134726625 15265 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 217515134726625 17011 0ustar00taitai000000000000Lexical-Accessor-1.001000/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; my $selfvar = shift || '$_[0]'; sprintf( q[ %s->{%s} ], $selfvar, $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; 91chain.t000664001750001750 265315134726625 15560 0ustar00taitai000000000000Lexical-Accessor-1.001000/t=pod =encoding utf-8 =head1 PURPOSE Test that chaining works =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2026 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; my $selfvar = shift || '$_[0]'; sprintf( q[ %s->{%s} ], $selfvar, $me->{slot}, ); } }; BEGIN { package Local::MyClass; use Local::MyAccessor; sub new { my $class = shift; bless { @_ }, $class; } has foo => (accessor => 'foo', clearer => 'clear_foo', writer => 'set_foo', chain => 1); has bar => (accessor => 'bar', clearer => 'clear_bar', writer => 'set_bar', chain => 0); }; 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 }, ); is( Local::MyClass->new(bar => 42)->foo(1)->set_foo(2)->clear_foo->clear_foo->bar, 42 ); is( Local::MyClass->new(bar => 42)->clear_bar, 42 ); is( Local::MyClass->new(bar => 42)->bar(66), 66 ); is( Local::MyClass->new(bar => 42)->set_bar(66), 66 ); done_testing; rt101024.t000664001750001750 115315134726625 15413 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 2567415134726625 20153 0ustar00taitai000000000000Lexical-Accessor-1.001000/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 = '1.001000'; our @EXPORT = qw/ lexical_has /; our @ISA = qw/ Sub::Accessor::Small /; sub _generate_lexical_has : method { my $me = shift; my $code = $me->_generate_has(@_); return Sub::Accessor::Small::set_subname( "$me\::lexical_has", $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(@_); ( $me->{package} and defined $me->{slot} ) ? Sub::Accessor::Small::set_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<< chain >> If set to true, then writer and clearer methods, plus accessor methods when setting a value, will return the original object as their return value. This makes it possible to do: my $result = $obj->$set_foo(1)->$set_bar(2)->some_method(); $obj->$clear_foo->$clear_bar; It is also possible to set C to an arrayref of which kinds of accessors are expected to be chainable. For example: C<< chain => [ 'clearer', 'writer' ] >>. Only 'clearer', 'writer', and 'accessor' are valid values in this arrayref. =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, 2025 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =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 6400615134726625 20363 0ustar00taitai000000000000Lexical-Accessor-1.001000/lib/Sub/Accessoruse 5.008003; use strict; use warnings; no warnings qw( void once uninitialized ); package Sub::Accessor::Small; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '1.001000'; our @ISA = qw/ Exporter::Tiny /; our @EXPORT_OK = qw/ has /; use Carp qw( carp croak ); use Eval::TypeTiny qw(); use Exporter::Tiny qw(); use Scalar::Util qw( blessed reftype ); 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 } ;; }; fieldhash( our %FIELDS ); my $set_subname_is_fake = 0; *set_subname = eval { require Sub::Util } ? \&Sub::Util::set_subname : eval { require Sub::Name } ? \&Sub::Name::subname : do { $set_subname_is_fake++; sub { pop; } }; 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; }; return set_subname( "$me\::has", $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 _create_child : method { my $me = shift; my $name = shift; return ref($me)->new_from_has( $name, $me->{package} ? (package => $me->{package}) : (), $me->{_export} ? (_export => $me->{_export}) : (), @_, ); } 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 make_var_name : method { my $me = shift; my $stem = shift; my $sigil = shift || '$'; my $varname = sprintf '%s_for_%s', $stem, $me->{slot}; $varname =~ s{([\WX])}{sprintf q{X%04XX}, ord($1)}eg; return $sigil . $varname; } 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 @pairs = $me->expand_handles; my %handles_map; while ( @pairs ) { my ( $name ) = splice( @pairs, 0, 2 ); $handles_map{"$name"} = $name; } require Sub::HandlesVia::Toolkit::SubAccessorSmall; my $SHV = 'Sub::HandlesVia::Toolkit::SubAccessorSmall'->new( attr => $me, handles_map => \%handles_map, ); $shv_data = $SHV->clean_spec( $me->{package}, $me->{slot}, +{%$me}, ); $shv_data and $SHV->install_delegations( $shv_data ); } 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 { ( ref($_) eq 'REF' or ref($_) eq 'SCALAR' ) ? ${$_} : $_ } $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"; no strict qw(refs); *$name = set_subname( $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 method name or 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/ _build_%s _build_%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' ) { croak "builder => CODE requires Sub::Util or Sub::Name to be installed" if $set_subname_is_fake; defined($name) && defined($me->{package}) or croak("Invalid builder; expected method name as string"); my $code = delete $me->{builder}; my $is_private = ($name =~ /\A_/) ? 1 : 0; my $subname = sprintf $one{builder}[$is_private], $name; $me->install_coderef( $subname, $code ); $me->{builder} = $subname; } } } sub canonicalize_is : method { my $me = shift; if ( $me->{is} eq 'lazy' ) { $me->{lazy} = 1 if !exists($me->{lazy}); $me->{builder} = 1 unless exists($me->{builder}) || exists($me->{default}); } defined( my $name = $me->{slot} ) or return; if ($me->{is} eq 'rw') { $me->{accessor} = $name unless exists $me->{accessor} or ( defined $me->{reader} and $me->{reader} eq $name ); } elsif ($me->{is} eq 'ro') { $me->{reader} = $name unless exists $me->{reader} or ( defined $me->{accessor} and $me->{accessor} eq $name ); } elsif ($me->{is} eq 'rwp') { $me->{reader} = $name unless exists $me->{reader} or ( defined $me->{accessor} and $me->{accessor} eq $name ); $me->{writer} = "_set_$name" unless exists $me->{writer}; } elsif ($me->{is} eq 'lazy') { $me->{reader} = $name unless exists $me->{reader} or ( defined $me->{accessor} and $me->{accessor} eq $name ); } } sub canonicalize_default : method { my $me = shift; return unless exists $me->{default}; my $ref = ref $me->{default}; if ( $ref eq 'ARRAY' and not @{$me->{default}} ) { $ref = 'SCALAR'; $me->{default} = \'[]'; } elsif ( $ref eq 'HASH' and not %{$me->{default}} ) { $ref = 'SCALAR'; $me->{default} = \'{}'; } !$ref or $ref =~ /^(CODE|SCALAR)$/ or croak("Invalid default; expected a non-reference, CODE ref, or SCALAR ref"); } sub canonicalize_isa : method { my $me = shift; if (my $does = $me->{does}) { $me->{isa} ||= sub { blessed($_[0]) && $_[0]->DOES($does) }; } if ( $me->{enum} ) { require Types::Standard; $me->{isa} = Types::Standard::Enum()->of( $me->{coerce} ? \1: (), @{$me->{enum}} ); } 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); } if ( 'CODE' eq ref $me->{isa} ) { require Type::Tiny; $me->{isa} = Type::Tiny->new( constraint => $me->{isa} ); } } sub canonicalize_trigger : method { my $me = shift; if ( defined $me->{trigger} ) { # Create an additional slot to hold a mutex, preventing the trigger # from triggering itself. This slot won't have any accessors, etc # so the slot name doesn't need to consist of wordlike characters. # Indeed, it's better to include a non-wordlike character to avoid # collisions. my $slot = sprintf( '%s:trigger_mutex', $me->{slot} ); $me->{trigger_mutex} = $me->_create_child( $slot ); } } sub canonicalize_chain : method { my $me = shift; my $okay = qr/^(accessor|writer|clearer)$/; if ( exists $me->{chain} ) { if ( 'ARRAY' eq ref $me->{chain} ) { croak("Unrecognized chain option") if grep { !/$okay/ } @{$me->{chain}}; } elsif ( ref $me->{chain} ) { croak("Unrecognized chain option"); } elsif ( $me->{chain} =~ $okay ) { $me->{chain} = [ $me->{chain} ] } elsif ( $me->{chain} eq '0' or $me->{chain} eq '1' or $me->{chain} eq '' ) { $me->{chain} = !!$me->{chain}; } else { croak("Unrecognized chain option"); } } } 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; $me->canonicalize_chain; } sub has_simple_accessor : method { my $me = shift; return !!0 if !$me->has_simple_reader; return !!0 if !$me->has_simple_writer; return !!1; } sub has_simple_reader : method { my $me = shift; return !!0 if $me->{lazy}; return !!1; } sub has_simple_writer : method { my $me = shift; return !!0 if exists $me->{trigger}; return !!0 if exists $me->{isa}; return !!0 if $me->{weak_ref}; return !!1; } sub has_simple_predicate : method { my $me = shift; return !!1; } sub has_simple_clearer : method { my $me = shift; return !!1; } sub has_chainable_writer : method { my $me = shift; return !!grep { $_ eq 'writer' } @{ $me->{chain} } if 'ARRAY' eq ref $me->{chain}; return !!$me->{chain}; } sub has_chainable_accessor : method { my $me = shift; return !!grep { $_ eq 'accessor' } @{ $me->{chain} } if 'ARRAY' eq ref $me->{chain}; return !!$me->{chain}; } sub has_chainable_clearer : method { my $me = shift; return !!grep { $_ eq 'clearer' } @{ $me->{chain} } if 'ARRAY' eq ref $me->{chain}; return !!$me->{chain}; } 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"; 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; my $selfvar = shift || '$_[0]'; my $maybe_chain = $me->has_chainable_clearer ? sub { $_[0] . "; $selfvar" } : sub { $_[0] }; $maybe_chain->( sprintf( q[ delete(%s) ], $me->inline_access( $selfvar ), ) ); } sub inline_access : method { my $me = shift; my $selfvar = shift || '$_[0]'; sprintf( q[ $Sub::Accessor::Small::FIELDS{%s}{%d} ], $selfvar, $me->{id}, ); } sub inline_access_w : method { my $me = shift; my $selfvar = shift || '$_[0]'; my $expr = shift || die; sprintf( q[ %s = %s ], $me->inline_access( $selfvar ), $expr, ); } sub predicate : method { my $me = shift; $me->inline_to_coderef( predicate => $me->inline_predicate, ); } sub inline_predicate : method { my $me = shift; my $selfvar = shift || '$_[0]'; sprintf( q[ exists(%s) ], $me->inline_access( $selfvar ), ); } 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 $selfvar = shift || '$_[0]'; my $method = shift || die; my $get = $me->inline_access( $selfvar ); my $varname = $me->make_var_name( 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_maybe_write_default( $selfvar ), $get, $death, $varname, ); } else { return sprintf( q[ %s; my $h = %s; %s; shift; $h->%s(@_) ], $me->inline_maybe_write_default( $selfvar ), $get, $death, $varname, ); } } sub inline_get : method { my $me = shift; my $selfvar = shift || '$_[0]'; my $get = $me->inline_access( $selfvar ); 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_maybe_write_default : method { my $me = shift; my $selfvar = shift || '$_[0]'; if ($me->{lazy}) { return sprintf( q[ %s unless %s; ], $me->inline_access_w( $selfvar, $me->inline_default( $selfvar ) ), $me->inline_predicate( $selfvar ), ); } return ''; } sub _is_bool ($) { my $value = shift; return !!0 unless defined $value; return !!0 if ref $value; return !!0 unless Scalar::Util::isdual( $value ); return !!1 if $value && "$value" eq '1' && $value+0 == 1; return !!1 if !$value && "$value" eq q'' && $value+0 == 0; return !!0; } sub _created_as_number ($) { my $value = shift; return !!0 if utf8::is_utf8($value); return !!0 unless defined $value; return !!0 if ref $value; require B; my $b_obj = B::svref_2object(\$value); my $flags = $b_obj->FLAGS; return !!1 if $flags & ( B::SVp_IOK() | B::SVp_NOK() ) and !( $flags & B::SVp_POK() ); return !!0; } sub _created_as_string ($) { my $value = shift; defined($value) && !ref($value) && !_is_bool($value) && !_created_as_number($value); } sub inline_default : method { my $me = shift; my $selfvar = shift || '$_[0]'; my $preferred_closeover_var = shift || $me->make_var_name('default'); if (exists $me->{default}) { my $ref = ref $me->{default}; if ( $ref eq 'CODE' ) { $me->{inline_environment}{$preferred_closeover_var} = \($me->{default}); return qq[$preferred_closeover_var\->($selfvar)]; } elsif ( $ref eq 'SCALAR' ) { return ${$me->{default}}; } elsif ( !defined $me->{default} ) { return 'undef'; } elsif ( _is_bool $me->{default} ) { return $me->{default} ? '!!1' : '!!0'; } elsif ( _created_as_number $me->{default} ) { return $me->{default} + 0; } elsif ( _created_as_string $me->{default} ) { require B; return B::perlstring( $me->{default} ); } } elsif (defined $me->{builder}) { return $selfvar . '->' . $me->{builder}; } return undef; } sub reader : method { my $me = shift; $me->inline_to_coderef( reader => $me->inline_reader, ); } sub inline_reader : method { my $me = shift; my $selfvar = shift || '$_[0]'; if ( $me->{lazy} ) { my $flag; delete local $me->{trigger}; my $w = $me->inline_writer( $selfvar, $me->inline_default( $selfvar ), \$flag ); if ( $flag ) { return sprintf( '( (%s) ? (%s) : (%s) )', $me->inline_predicate( $selfvar ), $me->inline_get( $selfvar ), $w, ); } else { return sprintf( '( (%s) ? (%s) : do { %s } )', $me->inline_predicate( $selfvar ), $me->inline_get( $selfvar ), $w, ); } } return $me->inline_get( $selfvar ); } sub writer : method { my $me = shift; $me->inline_to_coderef( writer => $me->inline_writer, ); } sub inline_writer : method { my $me = shift; my $selfvar = shift || '$_[0]'; my $expr = shift || '$_[1]'; my $flag = shift || undef; my $get = $me->inline_access( $selfvar ); my $coerce = $me->inline_type_coercion( $selfvar, $expr ); my $maybe_chain = $me->has_chainable_writer ? sub { $_[0] . "; $selfvar" } : sub { $_[0] }; # no coercion and simple variable if ($coerce eq $expr and $expr =~ /^\$\w+(?:[-][>])?(?:\[\d+\]|\{[^}]\})*$/) { if (!$me->{trigger} and !$me->{weak_ref}) { $$flag = 1 if $flag; return $maybe_chain->( $me->inline_access_w( $selfvar, $me->inline_type_assertion( $selfvar, $expr ), ) ); } elsif ( !$me->{weak_ref} ) { return sprintf( '%s; my @old = (%s) ? (%s) : (); %s; %s; %s', $me->inline_type_assertion( $selfvar, $expr ), $me->inline_predicate( $selfvar ), $me->inline_access( $selfvar ), $me->inline_access_w( $selfvar, $expr ), $me->inline_trigger( $selfvar, undef, '@old' ), $me->has_chainable_writer ? $selfvar : $me->inline_get( $selfvar ), ); } else { return sprintf( '%s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s', $me->inline_type_assertion( $selfvar, $expr ), $me->inline_predicate( $selfvar ), $me->inline_access( $selfvar ), $me->inline_access_w( $selfvar, $expr ), $me->inline_trigger( $selfvar, undef, '@old' ), $me->inline_weaken( $selfvar ), $me->has_chainable_writer ? $selfvar : $me->inline_get( $selfvar ), ); } } # Use intermediate variable to store result of coercion and/or default if ( !$me->{trigger} and !$me->{weak_ref} ) { my $ass = $me->inline_type_assertion( $selfvar, '$val' ); return $maybe_chain->( sprintf( 'my $val = %s; %s', $coerce, $me->inline_access_w( $selfvar, $ass =~ /^do/ ? $ass : "do { $ass }" ), ) ); } elsif ( !$me->{weak_ref} ) { return sprintf( 'my $val = %s; %s; my @old = (%s) ? (%s) : (); %s; %s; %s', $coerce, $me->inline_type_assertion( $selfvar, '$val' ), $me->inline_predicate( $selfvar ), $me->inline_access( $selfvar ), $me->inline_access_w( $selfvar, '$val' ), $me->inline_trigger( $selfvar, undef, '@old' ), $me->has_chainable_writer ? $selfvar : $me->inline_access( $selfvar ), ); } else { return sprintf( 'my $val = %s; %s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s', $coerce, $me->inline_type_assertion( $selfvar, '$val' ), $me->inline_predicate( $selfvar ), $me->inline_access( $selfvar ), $me->inline_access_w( $selfvar, '$val' ), $me->inline_trigger( $selfvar, undef, '@old' ), $me->inline_weaken( $selfvar ), $me->has_chainable_writer ? $selfvar : $me->inline_access( $selfvar ), ); } } sub accessor : method { my $me = shift; $me->inline_to_coderef( accessor => $me->inline_accessor, ); } sub inline_accessor : method { my $me = shift; my $selfvar = shift || '$_[0]'; my $expr = shift || '$_[1]'; my $toggle = shift || '@_ > 1'; my $get = $me->inline_access( $selfvar ); my $coerce = $me->inline_type_coercion( $selfvar, $expr ); my $maybe_chain = $me->has_chainable_accessor ? sub { $_[0] . "; $selfvar" } : sub { $_[0] }; if ($coerce eq $expr) # i.e. no coercion { if (!$me->{lazy} and !$me->{trigger} and !$me->{weak_ref}) { return sprintf( '(%s) ? (%s) : %s', $toggle, $me->has_chainable_accessor ? sprintf( 'do { %s; %s }', $me->inline_access_w( $selfvar, $me->inline_type_assertion( $selfvar, $expr ) ), $selfvar, ) : $me->inline_access_w( $selfvar, $me->inline_type_assertion( $selfvar, $expr ) ), $me->inline_get( $selfvar ), ); } return sprintf( 'if (%s) { %s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s } else { %s }', $toggle, $me->inline_type_assertion( $selfvar, $expr ), $me->inline_predicate( $selfvar ), $me->inline_access( $selfvar ), $me->inline_access_w( $selfvar, $expr ), $me->inline_trigger( $selfvar, undef, '@old' ), $me->inline_weaken( $selfvar ), $me->has_chainable_accessor ? $selfvar : $me->inline_reader( $selfvar ), $me->inline_reader( $selfvar ), ); } if ( !$me->{trigger} and !$me->{weak_ref} ) { return sprintf( 'if (%s) { my $val = %s; %s; %s; %s } else { %s }', $toggle, $coerce, $me->inline_type_assertion( $selfvar, '$val' ), $me->inline_access_w( $selfvar, '$val' ), $me->has_chainable_accessor ? $selfvar : $me->inline_reader( $selfvar ), $me->inline_reader( $selfvar ), ); } return sprintf( 'if (%s) { my $val = %s; %s; my @old = (%s) ? (%s) : (); %s; %s; %s; %s } else { %s }', $toggle, $coerce, $me->inline_type_assertion( $selfvar, '$val' ), $me->inline_predicate( $selfvar ), $me->inline_access( $selfvar ), $me->inline_access_w( $selfvar, '$val' ), $me->inline_trigger( $selfvar, undef, '@old' ), $me->inline_weaken( $selfvar ), $me->has_chainable_accessor ? $selfvar : $me->inline_reader( $selfvar ), $me->inline_reader( $selfvar ), ); } sub inline_type_coercion : method { my $me = shift; my $selfvar = shift || '$_[0]'; # usually ignored my $var = shift || die; 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 my $coercion_varname = $me->make_var_name('coercion'); $me->{inline_environment}{$coercion_varname} = \$coercion; if ( blessed($coercion) and $coercion->can('coerce') ) { return sprintf('%s->coerce(%s)', $coercion_varname, $var); } return sprintf('%s->(%s)', $coercion_varname, $var); } sub inline_type_assertion : method { my $me = shift; my $selfvar = shift || '$_[0]'; # usually ignored my $var = shift || die; 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 my $type_varname = $me->make_var_name('type'); $me->{inline_environment}{$type_varname} = \$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(%s->get_message(%s))', $type->$inliner($var), $var, $type_varname, $var); } } if ( blessed($type) and $type->can('check') and $type->can('get_message') ) { return sprintf('%s->check(%s) ? %s : Carp::croak(%s->get_message(%s))', $type_varname, $var, $var, $type_varname, $var); } return sprintf('%s->(%s) ? %s : Carp::croak("Value %s failed type constraint check")', $type_varname, $var, $var, $var); } sub inline_weaken : method { my $me = shift; my $selfvar = shift || '$_[0]'; return '' unless $me->{weak_ref}; sprintf( q[ Scalar::Util::weaken(%s) if ref(%s) ], $me->inline_access( $selfvar ), $me->inline_access( $selfvar ), ); } sub inline_trigger : method { my $me = shift; my $selfvar = shift || '$_[0]'; my $new = shift || $me->inline_access( $selfvar ); my $old = shift || ''; my $trigger = $me->{trigger} or return ''; my $run_trigger_code; if ( ref($trigger) ) { my $trigger_varname = $me->make_var_name('trigger'); $me->{inline_environment}{$trigger_varname} = \$trigger; $run_trigger_code = sprintf('%s->(%s, %s, %s)', $trigger_varname, $selfvar, $new, $old); } else { $run_trigger_code = sprintf('%s->%s(%s, %s)', $selfvar, $trigger, $new, $old); } # Need to assign invocant to a temp lexical variable in case it's still # (probably is!) $_[0] because the guard will not be able to close over # $_[0]. my $mutex = $me->{trigger_mutex}; return sprintf( '%s || do { my $tmp = %s; my $g = %s->new(sub { %s }); %s; %s }', $mutex->inline_access($selfvar), $selfvar, $mutex->_guard_class, $mutex->inline_clearer('$tmp'), # $mutex hasn't inherited `chain` option $mutex->inline_access_w($selfvar, '!!1'), $run_trigger_code, ); } sub _guard_class : method { return __PACKAGE__ . "::_Guard"; } { package #hide Sub::Accessor::Small::_Guard; sub new { bless( [ $_[1], $_[2] ], $_[0] ) } sub defang { $_[0][1] = ( @_==2 ? $_[1] : 1 ) } sub DESTROY { $_[0][0]->() unless $_[0][1] } } 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, 2025 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =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. SubAccessorSmall.pm000664001750001750 503115134726625 24372 0ustar00taitai000000000000Lexical-Accessor-1.001000/lib/Sub/HandlesVia/Toolkituse 5.008003; use strict; use warnings; no warnings qw( void once uninitialized ); package Sub::HandlesVia::Toolkit::SubAccessorSmall; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '1.001000'; use Sub::HandlesVia::Toolkit; our @ISA = 'Sub::HandlesVia::Toolkit'; $ISA[0]->VERSION( '0.025' ); sub new { my $class = shift; bless { @_ } => $class; } sub _attr { shift->{attr}; } sub _handles_map { shift->{handles_map}; } sub clean_spec { my ( $self, $target, $attr, $spec ) = @_; if ( 'ARRAY' eq ref $spec->{handles} ) { my %tmp = @{ $spec->{handles} }; $spec->{handles} = \%tmp; } return $self->SUPER::clean_spec( $target, $attr, $spec ); } sub code_generator_for_attribute { my ( $self, $target, $attr ) = @_; my $realattr = $self->_attr; my $handles_map = $self->_handles_map; my $captures = ( $realattr->{inline_environment} ||= {} ); my $slot = sub { my $gen = shift; $realattr->inline_access($gen->generate_self); }; my ( $get, $set, $get_is_lvalue ); if ( $realattr->has_simple_reader ) { $get = sub { my $gen = shift; return $realattr->inline_access($gen->generate_self); }; $get_is_lvalue = !!1; } else { $get = sub { my $gen = shift; return $realattr->inline_reader( $gen->generate_self ); } } if ( $realattr->has_simple_writer ) { $set = sub { my ( $gen, $val ) = @_; return sprintf('(%s)', $realattr->inline_access_w($gen->generate_self, $val) ); }; } else { $set = sub { my ( $gen, $val ) = @_; return $realattr->inline_writer( $gen->generate_self, $val ); }; } require Sub::HandlesVia::CodeGenerator; return 'Sub::HandlesVia::CodeGenerator'->new( toolkit => $self, target => $target, attribute => $attr, env => $captures, isa => $realattr->{isa}, coerce => $realattr->{coerce}, generator_for_get => $get, generator_for_set => $set, generator_for_slot => $slot, get_is_lvalue => $get_is_lvalue, set_checks_isa => !!1, set_strictly => !!0, method_installer => sub { my ( $method_name, $coderef ) = @_; my $real_destination = $handles_map->{$method_name}; $realattr->install_coderef( $real_destination, $coderef ); }, generator_for_default => sub { my ( $gen, $handler ) = @_ or die; if ( $handler and not $realattr->{builder} and not exists $realattr->{default} ) { return $handler->default_for_reset->(); } return $realattr->inline_default($gen->generate_self, '$default'); }, ); } 1;