constant-defer-6/0002755000175000017500000000000012471561714011723 5ustar ggggconstant-defer-6/COPYING0000644000175000017500000010437410641206144012753 0ustar gggg GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), 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 prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey 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; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. 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. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 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. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS 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 the public, 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 state 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) 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 3 of the License, 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program 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, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . constant-defer-6/Changes0000644000175000017500000000215212467553163013220 0ustar ggggCopyright 2009, 2010, 2011, 2015 Kevin Ryde This file is part of constant-defer. constant-defer 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 3, or (at your option) any later version. constant-defer 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 constant-defer. If not, see . Version 6, February 2015 - TEST_REQUIRES and test.suggests per Kent Fredric RT#102107 Version 5, February 2011 - fixes for perl 5.6 and earlier Version 4, September 2010 - docs clarify not inlined, as suggested by Adam Kennedy Version 3, September 2010 - test manifest only as an author test Version 2, October 2009 - avoid a circular ref in the initial sub created Version 1, September 2009 - the first version constant-defer-6/xtools/0002755000175000017500000000000012471561714013253 5ustar ggggconstant-defer-6/xtools/my-check-spelling.sh0000755000175000017500000000320612350135425017114 0ustar gggg#!/bin/sh # my-check-spelling.sh -- grep for spelling errors # Copyright 2009, 2010, 2011, 2012, 2013, 2014 Kevin Ryde # my-check-spelling.sh is shared by several distributions. # # my-check-spelling.sh 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 3, or (at your option) any later # version. # # my-check-spelling.sh 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 file. If not, see . set -e # set -x # | tee /dev/stdout # -name samp -prune \ # -o -name formats -prune \ # -o -name "*~" -prune \ # -o -name "*.tar.gz" -prune \ # -o -name "*.deb" -prune \ # -o # -o -name dist-deb -prune \ # | egrep -v '(Makefile|dist-deb)' \ if find . -name my-check-spelling.sh -prune \ -o -type f -print0 \ | xargs -0 egrep --color=always -nHi 'optino|recurrance|nineth|\bon on\b|\bto to\b|tranpose|adjustement|glpyh|rectanglar|availabe|grabing|cusor|refering|writeable|nineth|\bommitt?ed|omited|[$][rd]elf|requrie|noticable|continous|existant|explict|agument|destionation|\bthe the\b|\bfor for\b|\bare have\b|\bare are\b|\bwith with\b|\bin in\b|\b[tw]hen then\b|\bnote sure\b|\bnote yet\b|correspondance|sprial|wholely|satisif|\bteh\b|\btje\b' then # nothing found exit 1 else exit 0 fi constant-defer-6/xtools/my-deb.sh0000755000175000017500000000702412332027136014757 0ustar gggg#!/bin/sh # my-deb.sh -- make .deb # Copyright 2009, 2010, 2011, 2012, 2013, 2014 Kevin Ryde # my-deb.sh is shared by several distributions. # # my-deb.sh 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 3, or (at your option) any later # version. # # my-deb.sh 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 file. If not, see . # warnings::unused broken by perl 5.14, so use 5.10 for checks set -e set -x DISTNAME=`sed -n 's/^DISTNAME = \(.*\)/\1/p' Makefile` if test -z "$DISTNAME"; then echo "DISTNAME not found" exit 1 fi DISTVNAME=`sed -n 's/^DISTVNAME = \(.*\)/\1/p' Makefile` if test -z "$DISTVNAME"; then echo "DISTVNAME not found" exit 1 fi VERSION=`sed -n 's/^VERSION = \(.*\)/\1/p' Makefile` if test -z "$VERSION"; then echo "VERSION not found" exit 1 fi XS_FILES=`sed -n 's/^XS_FILES = \(.*\)/\1/p' Makefile` EXE_FILES=`sed -n 's/^EXE_FILES = \(.*\)/\1/p' Makefile` if test -z "$XS_FILES" then DPKG_ARCH=all else DPKG_ARCH=`dpkg --print-architecture` fi # programs named after the dist, libraries named with "lib" # gtk2-ex-splash and wx-perl-podbrowser programs are lib too though DEBNAME=`echo $DISTNAME | tr A-Z a-z` case "$EXE_FILES" in gtk2-ex-splash|wx-perl-podbrowser|'') DEBNAME="lib${DEBNAME}-perl" ;; esac DEBVNAME="${DEBNAME}_$VERSION-0.1" DEBFILE="${DEBVNAME}_$DPKG_ARCH.deb" # ExtUtils::MakeMaker 6.42 of perl 5.10.0 makes "$(DISTVNAME).tar.gz" depend # on "$(DISTVNAME)" distdir directory, which is always non-existent after a # successful dist build, so the .tar.gz is always rebuilt. # # So although the .deb depends on the .tar.gz don't express that here or it # rebuilds the .tar.gz every time. # # The right rule for the .tar.gz would be to depend on the files which go # into it of course ... # # DISPLAY is unset for making a deb since under fakeroot gtk stuff may try # to read config files like ~/.pangorc from root's home dir /root/.pangorc, # and that dir will be unreadable by ordinary users (normally), provoking # warnings and possible failures from nowarnings(). # test -f $DISTVNAME.tar.gz || make $DISTVNAME.tar.gz debver="`dpkg-parsechangelog -c1 | sed -n -r -e 's/^Version: (.*)-[0-9.]+$/\1/p'`" echo "debver $debver", want $VERSION test "$debver" = "$VERSION" rm -rf $DISTVNAME tar xfz $DISTVNAME.tar.gz unset DISPLAY; export DISPLAY cd $DISTVNAME dpkg-checkbuilddeps debian/control fakeroot debian/rules binary cd .. rm -rf $DISTVNAME #------------------------------------------------------------------------------ # lintian .deb and source lintian -I -i \ --suppress-tags new-package-should-close-itp-bug,desktop-entry-contains-encoding-key \ $DEBFILE TEMP="/tmp/temp-lintian-$DISTVNAME" rm -rf $TEMP mkdir $TEMP cp $DISTVNAME.tar.gz $TEMP/${DEBNAME}_$VERSION.orig.tar.gz cd $TEMP tar xfz ${DEBNAME}_$VERSION.orig.tar.gz if test "$DISTVNAME" != "$DEBNAME-$VERSION"; then mv -T $DISTVNAME $DEBNAME-$VERSION fi dpkg-source -b $DEBNAME-$VERSION \ ${DEBNAME}_$VERSION.orig.tar.gz; \ lintian -I -i \ --suppress-tags maintainer-upload-has-incorrect-version-number,changelog-should-mention-nmu,empty-debian-diff,debian-rules-uses-deprecated-makefile *.dsc cd / rm -rf $TEMP exit 0 constant-defer-6/xtools/my-check-copyright-years.sh0000755000175000017500000000435312464334463020445 0ustar gggg#!/bin/sh # my-check-copyright-years.sh -- check copyright years in dist # Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015 Kevin Ryde # my-check-copyright-years.sh is shared by several distributions. # # my-check-copyright-years.sh 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 3, or (at your # option) any later version. # # my-check-copyright-years.sh 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 file. If not, see . set -e # die on error set -x # echo # find files in the dist with mod times this year, but without this year in # the copyright line if test -z "$DISTVNAME"; then DISTVNAME=`sed -n 's/^DISTVNAME = \(.*\)/\1/p' Makefile` fi if test -z "$DISTVNAME"; then echo "DISTVNAME not set and not in Makefile" exit 1 fi TARGZ="$DISTVNAME.tar.gz" if test -e "$TARGZ"; then :; else pwd echo "TARGZ $TARGZ not found" exit 1 fi MY_HIDE= year=`date +%Y` result=0 # files with dates $year tar tvfz $TARGZ \ | egrep "$year-|debian/copyright" \ | sed "s:^.*$DISTVNAME/::" \ | { while read i do # echo "consider $i" GREP=grep case $i in \ '' | */ \ | ppport.h \ | debian/changelog | debian/doc-base \ | debian/compat | debian/emacsen-compat | debian/source/format \ | debian/patches/*.diff \ | COPYING | MANIFEST* | SIGNATURE | META.yml | META.json \ | version.texi | */version.texi \ | *utf16* | examples/rs''s2lea''fnode.conf \ | */MathI''mage/ln2.gz | */MathI''mage/pi.gz \ | *.mo | *.locatedb* | t/samp.* \ | t/empty.dat | t/*.xpm | t/*.xbm | t/*.jpg | t/*.gif \ | t/*.g${MY_HIDE}d \ | */_whizzy*) continue ;; *.gz) GREP=zgrep esac; \ if test -e "$srcdir/$i" then f="$srcdir/$i" else f="$i" fi if $GREP -q -e "Copyright.*$year" $f then :; else echo "$i:1: this file" grep Copyright $f result=1 fi done } exit $result constant-defer-6/xt/0002755000175000017500000000000012471561714012356 5ustar ggggconstant-defer-6/xt/0-Test-ConsistentVersion.t0000644000175000017500000000225311655356324017316 0ustar gggg#!/usr/bin/perl -w # 0-Test-ConsistentVersion.t -- run Test::ConsistentVersion if available # Copyright 2011 Kevin Ryde # 0-Test-ConsistentVersion.t is shared by several distributions. # # 0-Test-ConsistentVersion.t 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 3, or (at your option) any # later version. # # 0-Test-ConsistentVersion.t 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 file. If not, see . use 5.004; use strict; use Test::More; eval { require Test::ConsistentVersion } or plan skip_all => "due to Test::ConsistentVersion not available -- $@"; Test::ConsistentVersion::check_consistent_versions (no_readme => 1, # no version number in my READMEs no_pod => 1, # no version number in my docs, at the moment ); # ! -e 'README'); exit 0; constant-defer-6/xt/0-Test-Synopsis.t0000755000175000017500000000176411655356314015456 0ustar gggg#!/usr/bin/perl -w # 0-Test-Synopsis.t -- run Test::Synopsis if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-Synopsis.t is shared by several distributions. # # 0-Test-Synopsis.t 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 3, or (at your option) any later # version. # # 0-Test-Synopsis.t 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 file. If not, see . use 5.004; use strict; use Test::More; eval 'use Test::Synopsis; 1' or plan skip_all => "due to Test::Synopsis not available -- $@"; ## no critic (ProhibitCallsToUndeclaredSubs) all_synopsis_ok(); exit 0; constant-defer-6/xt/0-no-debug-left-on.t0000755000175000017500000000651512044143060015734 0ustar gggg#!/usr/bin/perl -w # 0-no-debug-left-on.t -- check no Smart::Comments left on # Copyright 2011, 2012 Kevin Ryde # 0-no-debug-left-on.t is shared by several distributions. # # 0-no-debug-left-on.t 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 3, or (at your option) any # later version. # # 0-no-debug-left-on.t 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 file. If not, see . # cf Test::NoSmartComments which uses Module::ScanDeps. require 5; use strict; Test::NoDebugLeftOn->Test_More(verbose => 0); exit 0; package Test::NoDebugLeftOn; use strict; use ExtUtils::Manifest; sub Test_More { my ($class, %options) = @_; require Test::More; Test::More::plan (tests => 1); Test::More::ok ($class->check (diag => \&Test::More::diag, %options)); 1; } sub check { my ($class, %options) = @_; my $diag = $options{'diag'}; if (! -e 'Makefile.PL') { &$diag ('skip, no Makefile.PL so not ExtUtils::MakeMaker'); return 1; } my $href = ExtUtils::Manifest::maniread(); my @files = keys %$href; my $good = 1; my @perl_files = grep {m{ ^lib/ |^(lib|examples|x?t)/.*\.(p[lm]|t)$ |^Makefile.PL$ |^[^/]+$ }x } @files; my $filename; foreach $filename (@perl_files) { if ($options{'verbose'}) { &$diag ("perl file ",$filename); } if (! open FH, "< $filename") { &$diag ("Oops, cannot open $filename: $!"); $good = 0; next; } while () { if (/^__END__/) { last; } # only a DEBUG=> non-zero number is bad, so an expression can copy a # debug from another package if (/(DEBUG\s*=>\s*[1-9][0-9]*)/ || /^[ \t]*((use|no) (Smart|Devel)::Comments)/ || /^[ \t]*(use lib\b.*devel.*)/ ) { print STDERR "\n$filename:$.: leftover: $_\n"; $good = 0; } } if (! close FH) { &$diag ("Oops, error closing $filename: $!"); $good = 0; next; } } my @C_files = grep {m{ # toplevel or lib .c and .xs files ^[^/]*\.([ch]|xs)$ |^(lib|examples|x?t)/.*\.([ch]|xs)$ }x } @files; foreach $filename (@C_files) { if ($options{'verbose'}) { &$diag ("C/XS file ",$filename); } if (! open FH, "< $filename") { &$diag ("Oops, cannot open $filename: $!"); $good = 0; next; } while () { if (/^#\s*define\s+DEBUG\s+[1-9]/ ) { print STDERR "\n$filename:$.: leftover: $_\n"; $good = 0; } } if (! close FH) { &$diag ("Oops, error closing $filename: $!"); $good = 0; next; } } &$diag ("checked ",scalar(@perl_files)," perl files, ", scalar(@C_files)," C/XS files\n"); return $good; } constant-defer-6/xt/0-file-is-part-of.t0000644000175000017500000000576612136177231015605 0ustar gggg#!/usr/bin/perl -w # Copyright 2011, 2012, 2013 Kevin Ryde # 0-file-is-part-of.t is shared by several distributions. # # 0-file-is-part-of.t 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 3, or (at your option) any # later version. # # 0-file-is-part-of.t 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 file. If not, see . require 5; use strict; use Test::More tests => 1; use lib 't'; use MyTestHelpers; BEGIN { MyTestHelpers::nowarnings(); } ok (Test::FileIsPartOfDist->check(verbose=>1), 'Test::FileIsPartOfDist'); exit 0; package Test::FileIsPartOfDist; BEGIN { require 5 } use strict; use ExtUtils::Manifest; use File::Slurp; sub import { my $class = shift; my $arg; foreach $arg (@_) { if ($arg eq '-test') { require Test; Test::plan(tests=>1); is ($class->check, 1, 'Test::FileIsPartOfDist'); } } return 1; } sub new { my $class = shift; return bless { @_ }, $class; } sub check { my $class = shift; my $self = $class->new(@_); my $manifest = ExtUtils::Manifest::maniread(); if (! $manifest) { $self->diag("no MANIFEST perhaps"); return 0; } my @filenames = keys %$manifest; my $distname = $self->makefile_distname; if (! defined $distname) { $self->diag("Oops, DISTNAME not found in Makefile"); return 0; } if ($self->{'verbose'}) { $self->diag("DISTNAME $distname"); } my $good = 1; my $filename; foreach $filename (@filenames) { if (! $self->check_file_is_part_of($filename,$distname)) { $good = 0; } } return $good; } sub makefile_distname { my ($self) = @_; my $filename = "Makefile"; my $content = File::Slurp::read_file ($filename); if (! defined $content) { $self->diag("Cannot read $filename: $!"); return undef; } my $distname; if ($content =~ /^DISTNAME\s*=\s*([^#\n]*)/m) { $distname = $1; $distname =~ s/\s+$//; } return $distname; } sub check_file_is_part_of { my ($self, $filename, $distname) = @_; my $content = File::Slurp::read_file ($filename); if (! defined $content) { $self->diag("Cannot read $filename: $!"); return 0; } $content =~ /([T]his file is part of[^\n]*)/i or return 1; my $got = $1; if ($got =~ /[T]his file is part of \Q$distname/i) { return 1; } $self->diag("$filename: $got"); $self->diag("expected DISTNAME: $distname"); return 0; } sub diag { my $self = shift; my $func = $self->{'diag_func'} || eval { Test::More->can('diag') } || \&_diag; &$func(@_); } sub _diag { my $msg = join('', map {defined($_)?$_:'[undef]'} @_)."\n"; $msg =~ s/^/# /mg; print STDERR $msg; } constant-defer-6/xt/0-Test-DistManifest.t0000755000175000017500000000231111655356331016205 0ustar gggg#!/usr/bin/perl -w # 0-Test-DistManifest.t -- run Test::DistManifest if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-DistManifest.t is shared by several distributions. # # 0-Test-DistManifest.t 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 3, or (at your option) any # later version. # # 0-Test-DistManifest.t 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 file. If not, see . use 5.004; use strict; use Test::More; # This is only an author test really and it only really does much in a # working directory where newly added files will exist. In a dist dir # something would have to be badly wrong for the manifest to be off. eval { require Test::DistManifest } or plan skip_all => "due to Test::DistManifest not available -- $@"; Test::DistManifest::manifest_ok(); exit 0; constant-defer-6/xt/0-examples-xrefs.t0000644000175000017500000000430012230011245015614 0ustar gggg#!/usr/bin/perl -w # Copyright 2011, 2013 Kevin Ryde # 0-examples-xrefs.t is shared by several distributions. # # 0-examples-xrefs.t 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 3, or (at your option) any # later version. # # 0-examples-xrefs.t 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 file. If not, see . BEGIN { require 5 } use strict; use ExtUtils::Manifest; use Test::More; use lib 't'; use MyTestHelpers; BEGIN { MyTestHelpers::nowarnings(); } my $manifest = ExtUtils::Manifest::maniread(); my @example_files = grep m{examples/.*\.pl$}, keys %$manifest; my @lib_files = grep m{lib/.*\.(pm|pod)$}, keys %$manifest; sub any_file_contains_example { my ($example) = @_; my $filename; foreach $filename (@lib_files) { if (pod_contains_example($filename, $example)) { return 1; } } foreach $filename (@example_files) { if ($filename ne $example && raw_contains_example($filename, $example)) { return 1; } } return 0; } sub pod_contains_example { my ($filename, $example) = @_; open FH, "< $filename" or die "Cannot open $filename: $!"; my $content = do { local $/; }; # slurp close FH or die "Error closing $filename: $!"; return scalar ($content =~ /F<\Q$example\E> |F\s+directory /xs); } sub raw_contains_example { my ($filename, $example) = @_; $example =~ s{^examples/}{}; open FH, "< $filename" or die "Cannot open $filename: $!"; my $ret = scalar (grep /\b\Q$example\E\b/, ); close FH or die "Error closing $filename: $!"; return $ret > 0; } plan tests => scalar(@example_files) + 1; my $example; foreach $example (@example_files) { is (any_file_contains_example($example), 1, "$example mentioned in some lib/ file"); } ok(1); exit 0; constant-defer-6/xt/0-Test-YAML-Meta.t0000755000175000017500000000345512347217470015252 0ustar gggg#!/usr/bin/perl -w # 0-Test-YAML-Meta.t -- run Test::CPAN::Meta::YAML if available # Copyright 2009, 2010, 2011, 2013, 2014 Kevin Ryde # 0-Test-YAML-Meta.t is shared by several distributions. # # 0-Test-YAML-Meta.t 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 3, or (at your option) any later # version. # # 0-Test-YAML-Meta.t 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 file. If not, see . use 5.004; use strict; use Test::More; my $meta_filename = 'META.yml'; unless (-e $meta_filename) { plan skip_all => "$meta_filename doesn't exist -- assume this is a working directory not a dist"; } plan tests => 3; SKIP: { eval { require CPAN::Meta::Validator; 1 } or skip "due to CPAN::Meta::Validator not available -- $@"; eval { require YAML; 1 } or skip "due to YAML module not available -- $@", 1; diag "CPAN::Meta::Validator version ", CPAN::Meta::Validator->VERSION; my $struct = YAML::LoadFile ($meta_filename); my $cmv = CPAN::Meta::Validator->new($struct); ok ($cmv->is_valid); if (! $cmv->is_valid) { diag "CPAN::Meta::Validator errors:"; foreach ($cmv->errors) { diag $_; } } } { # Test::CPAN::Meta::YAML version 0.15 for upper case "optional_features" names # eval 'use Test::CPAN::Meta::YAML 0.15; 1' or plan skip_all => "due to Test::CPAN::Meta::YAML 0.15 not available -- $@"; Test::CPAN::Meta::YAML::meta_spec_ok('META.yml'); } exit 0; constant-defer-6/xt/0-META-read.t0000755000175000017500000001071512136177162014342 0ustar gggg#!/usr/bin/perl -w # 0-META-read.t -- check META.yml can be read by various YAML modules # Copyright 2009, 2010, 2011, 2012, 2013 Kevin Ryde # 0-META-read.t is shared among several distributions. # # 0-META-read.t 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 3, or (at your option) any later # version. # # 0-META-read.t 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 file. If not, see . use 5.005; use strict; use Test::More; use lib 't'; use MyTestHelpers; BEGIN { MyTestHelpers::nowarnings(); } # When some of META.yml is generated by explicit text in Makefile.PL it can # be easy to make a mistake in the syntax, or indentation, etc, so the idea # here is to check it's readable from some of the YAML readers. # # The various readers differ in how strictly they look at the syntax. # There's no attempt here to say one of them is best or tightest or # whatever, just see that they all work. # # See 0-Test-YAML-Meta.t for Test::YAML::Meta which looks into field # contents, as well as maybe the YAML formatting. my $meta_filename; # allow for ancient perl, maybe eval { require FindBin; 1 } # new in 5.004 or plan skip_all => "FindBin not available -- $@"; eval { require File::Spec; 1 } # new in 5.005 or plan skip_all => "File::Spec not available -- $@"; diag "FindBin $FindBin::Bin"; $meta_filename = File::Spec->catfile ($FindBin::Bin, File::Spec->updir, 'META.yml'); -e $meta_filename or plan skip_all => "$meta_filename doesn't exist -- assume this is a working directory not a dist"; plan tests => 5; SKIP: { eval { require YAML; 1 } or skip "due to YAML module not available -- $@", 1; my $ok = eval { YAML::LoadFile ($meta_filename); 1 } or diag "YAML::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with YAML module"); } # YAML 0.68 is in fact YAML::Old, or something weird -- don't think they can # load together # # SKIP: { # eval { require YAML::Old; 1 } # or skip 'due to YAML::Old not available -- $@', 1; # # eval { YAML::Old::LoadFile ($meta_filename) }; # is ($@, '', # "Read $meta_filename with YAML::Old"); # } SKIP: { eval { require YAML::Syck; 1 } or skip "due to YAML::Syck not available -- $@", 1; my $ok = eval { YAML::Syck::LoadFile ($meta_filename); 1 } or diag "YAML::Syck::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with YAML::Syck"); } SKIP: { eval { require YAML::Tiny; 1 } or skip "due to YAML::Tiny not available -- $@", 1; my $ok = eval { YAML::Tiny->read ($meta_filename); 1 } or diag "YAML::Tiny->read() error -- $@"; ok ($ok, "Read $meta_filename with YAML::Tiny"); } SKIP: { eval { require YAML::XS; 1 } or skip "due to YAML::XS not available -- $@", 1; my $ok = eval { YAML::XS::LoadFile ($meta_filename); 1 } or diag "YAML::XS::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with YAML::XS"); } # Parse::CPAN::Meta describes itself for use on "typical" META.yml, so not # sure if demanding it works will more exercise its subset of yaml than the # correctness of our META.yml. At any rate might like to know if it fails, # so as to avoid tricky yaml for everyone's benefit, maybe. # SKIP: { eval { require Parse::CPAN::Meta; 1 } or skip "due to Parse::CPAN::Meta not available -- $@", 1; my $ok = eval { Parse::CPAN::Meta::LoadFile ($meta_filename); 1 } or diag "Parse::CPAN::Meta::LoadFile() error -- $@"; ok ($ok, "Read $meta_filename with Parse::CPAN::Meta::LoadFile"); } # Data::YAML::Reader 0.06 doesn't like header "--- #YAML:1.0" with the # # part produced by other YAML writers, so skip for now # # SKIP: { # eval { require Data::YAML::Reader; 1 } # or skip 'due to Data::YAML::Reader not available -- $@', 1; # # my $reader = Data::YAML::Reader->new; # open my $fh, '<', $meta_filename # or die "Cannot open $meta_filename"; # my $str = do { local $/=undef; <$fh> }; # close $fh or die; # # # if ($str !~ /\.\.\.$/) { # # $str .= "..."; # # } # my @lines = split /\n/, $str; # push @lines, "..."; # use Data::Dumper; # print Dumper(\@lines); # # # { local $,="\n"; print @lines,"\n"; } exit 0; constant-defer-6/xt/0-Test-Pod.t0000755000175000017500000000175111655356337014352 0ustar gggg#!/usr/bin/perl -w # 0-Test-Pod.t -- run Test::Pod if available # Copyright 2009, 2010, 2011 Kevin Ryde # 0-Test-Pod.t is shared by several distributions. # # 0-Test-Pod.t 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 3, or (at your option) any later # version. # # 0-Test-Pod.t 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 file. If not, see . use 5.004; use strict; use Test::More; # all_pod_files_ok() is new in Test::Pod 1.00 # eval 'use Test::Pod 1.00; 1' or plan skip_all => "due to Test::Pod 1.00 not available -- $@"; Test::Pod::all_pod_files_ok(); exit 0; constant-defer-6/Makefile.PL0000755000175000017500000000337712467563536013721 0ustar gggg#!/usr/bin/perl -w # Copyright 2009, 2011, 2012, 2014, 2015 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any # later version. # # constant-defer 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 constant-defer. If not, see . use strict; use ExtUtils::MakeMaker; WriteMakefile (NAME => 'constant::defer', ABSTRACT => 'Constant subs with deferred value calculation.', VERSION_FROM => 'lib/constant/defer.pm', PREREQ_PM => { vars => 0, }, TEST_REQUIRES => { Test => 0, # lib.pm is in the core but declare it here so # Module::Mask::Deps knows it's needed lib => 0, }, AUTHOR => 'Kevin Ryde ', LICENSE => 'gpl_3', SIGN => 1, # probably anything MIN_PERL_VERSION => '5', META_MERGE => { 'meta-spec' => { version => 2 }, no_index => { directory=>['devel','xt'] }, resources => { homepage => 'http://user42.tuxfamily.org/constant-defer/index.html', license => 'http://www.gnu.org/licenses/gpl.html', }, prereqs => { test => { suggests => { 'Scalar::Util' => 0, # for weaken() checking } }, }, }, ); exit 0; constant-defer-6/examples/0002755000175000017500000000000012471561714013541 5ustar ggggconstant-defer-6/examples/simple.pl0000755000175000017500000000162711524150764015373 0ustar gggg#!/usr/bin/perl -w # Copyright 2009, 2010, 2011 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any # later version. # # constant-defer 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 constant-defer. If not, see . use strict; use constant::defer FOO => sub { print "now calculating FOO ...\n"; print " ... done\n"; return 12345; }; printf "FOO is %d\n", FOO; printf "FOO is %d\n", FOO; exit 0; constant-defer-6/examples/instance.pl0000755000175000017500000000424412467555056015716 0ustar gggg#!/usr/bin/perl -w # Copyright 2009, 2010, 2011, 2015 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any # later version. # # constant-defer 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 constant-defer. If not, see . # Usage: perl instance.pl # # This program is an example of how to press constant::defer into service # for a once-only "singleton" object instance creation. # # The creation code here is entirely within the instance() routine so after # it's run it's discarded, which may save a few bytes of memory. If you # wanted other non-singleton object instances as well as the shared one then # you'd make a separate new() in the usual way. # # The $class parameter can help subclassing. A call like # # MyClass::SubClass->instance # # blesses into the given subclass name. But effectively there's only one # instance behind the two MyClass and MyClass::SubClass and whichever runs # first is the class created. If you only ever want one of the two then # that can be fine, otherwise it might be very confusing. # # Further arguments could be passed to the instance() creation, but they # affect the first call, so may be more confusing than flexible. # # Generally Class::Singleton or Class::Singleton::Weak are better for this # sort of thing, but if you have constant::defer for other uses anyway then # this is compact and cute. # package MyClass; use strict; use constant::defer instance => sub { my ($class) = @_; return bless { foo => 123 }, $class; }; sub do_something { print "do something ...\n"; } package main; printf "instance %s\n", MyClass->instance; printf "instance %s\n", MyClass->instance; my $obj = MyClass->instance; $obj->do_something; exit 0; constant-defer-6/inc/0002755000175000017500000000000012471561714012474 5ustar ggggconstant-defer-6/inc/my_pod2html0000755000175000017500000000750712175610062014657 0ustar gggg#!/usr/bin/perl # my_pod2html -- convert POD to HTML, with some mangling # Copyright 2009, 2010, 2011, 2013 Kevin Ryde # my_pod2html is shared by several distributions. # # my_pod2html 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 3, or (at your option) any later # version. # # my_pod2html 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 file. If not, see . use strict; use warnings; #use Smart::Comments; my $pod2html = MyPod2HTML->new; #

and

both too big, in mozilla at least $pod2html->html_h_level(3); $pod2html->parse_from_file(@ARGV); exit 0; package MyPod2HTML; use base 'Pod::Simple::HTML'; our $VERSION = 1; use constant DEBUG => 0; my %table = ('apt-file' => 'http://packages.debian.org/apt-file', 'apt-cache' => 'http://packages.debian.org/apt', 'apt-rdepends' => 'http://packages.debian.org/apt-rdepends', 'gtk-options' => 'http://manpages.ubuntu.com/manpages/jaunty/man7/gtk-options.7.html', 'xsetroot' => 'http://www.x.org/archive/X1'.'1R7.5/doc/man/man1/xsetroot.1.html', 'leafnode' => 'http://leafnode.sourceforge.net', 'lynx' => 'http://lynx.isc.org/', 'feed2imap' => 'http://home.gna.org/feed2imap', # disguise from grep 'rss'.'2email' => 'http://rss'.'2email.infogami.com', 'rssdrop' => 'http://search.cpan.org/dist/rssdrop/', 'toursst' => 'http://packages.debian.org/etch/toursst', 'netrc' => 'http://linux.die.net/man/5/netrc', # no online man pages apparently at http://man-db.nongnu.org/ 'man' => 'http://ftp.parisc-linux.org/cgi-bin/man/man2html?man+1', 'lexgrog' => 'http://ftp.parisc-linux.org/cgi-bin/man/man2html?lexgrog+1', 'apropos' => 'http://ftp.parisc-linux.org/cgi-bin/man/man2html?apropos+1', ); sub resolve_man_page_link { my ($self, $to, $frag) = @_; $to = "$to"; # Pod::Simple::LinkSection object ### $to if (my ($page, $section) = ($to =~ /(.*)\(\d+\)$/)) { ### $page if (my $url = $table{$page}) { return $url; } } return shift->SUPER::resolve_man_page_link (@_); } sub resolve_pod_link_by_table { my ($self, $to, $section) = @_; my $url; if (defined $to) { if ($to eq 'AptPkg') { $url = 'http://packages.debian.org/libapt-pkg-perl'; } if ($to =~ /^Glib::Ex::(SourceIds|SignalIds|FreezeNotify|TieProperties)/) { $url = "http://user42.tuxfamily.org/glib-ex-ob"."jectbits/$1.html"; } if ($to eq 'Gtk2::Ex::Widget'.'Cursor') { $url = 'http://user42.tuxfamily.org/gtk2-ex-widget'.'cursor/Widget'.'Cursor.html'; } if ($to eq 'Ti'.'e:'.':TZ') { $url = 'http://user42.tuxfamily.org/ti'.'e-'.'tz/TZ.html'; } if ($to eq 'Time:'.':TZ') { $url = 'http://user42.tuxfamily.org/ti'.'e-'.'tz/Time-'.'TZ.html'; } if ($to =~ /^(Glib|Gtk2)($|::(?!Ex::))/) { $to =~ s{::}{/}; $url = "http://gtk2-perl.sourceforge.net/doc/pod/$to.html" } if (defined $url) { return ($url . (defined $section && $section ne '' ? "#$section" : '')); } } return $self->SUPER::resolve_pod_link_by_table($to, $section); } # sub do_pod_link { # my($self, $link) = @_; # if (DEBUG) { # print "\nlink tag=",$link->tagname," type=",$link->attr('type'),"\n"; # print " to=",$link->attr('to')||'[none]',"\n"; # print " section=",$link->attr('section')||'[none]',"\n"; # } # # my $to = $link->attr('to') || ''; # undef if internal link # # return $self->SUPER::do_pod_link($link); # } constant-defer-6/devel/0002755000175000017500000000000012471561714013022 5ustar ggggconstant-defer-6/devel/constant-lexical.pl0000644000175000017500000000215212467557543016637 0ustar gggg#!/usr/bin/perl -w # Copyright 2015 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Smart::Comments; { package Foo; use constant FOO => 123; use constant BAR => 456; print FOO +1; print "\n"; } { package Foo; use constant::lexical FOO => 123; use constant::lexical BAR => 456; print FOO +1; print "\n"; sub S { 456 }; sub T () { 456 }; ### proto FOO: prototype(\&FOO) ### proto S: prototype(\&S) ### proto T: prototype(\&T) exit 0; } constant-defer-6/devel/circular.pl0000644000175000017500000000264711424406742015166 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; { use constant::defer foo => sub { print "foo runs\n"; 123 }; my $x = \&foo; { no warnings 'redefine'; *foo = sub () { print "new foo runs\n"; 456 }; } require Scalar::Util; print "func ",$x//'undef',"\n"; Scalar::Util::weaken ($x); print "func ",$x//'undef',"\n"; my $y = $constant::defer::DEBUG_LAST_RUNNER; undef $constant::defer::DEBUG_LAST_RUNNER; print "runner ",($y//'undef'),"\n"; Scalar::Util::weaken ($y); print "runner ",($y//'undef'),"\n"; # if (defined $y) { # print "y value ",$y->(),"\n"; # print "runner ",($y//'undef'),"\n"; # } if (defined $y) { require Devel::FindRef; print Devel::FindRef::track($y); } exit 0; } constant-defer-6/devel/MyConstantDeferExport.pm0000644000175000017500000000177311415713324017626 0ustar gggg# Copyright 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . package MyConstantDeferExport; use base 'Exporter'; our @EXPORT_OK = ('my_ctime'); use constant::defer my_ctime => sub { print "my_ctime runs\n"; require POSIX; return POSIX::ctime(time()); }; 1; __END__ constant-defer-6/devel/Singleton/0002755000175000017500000000000012471561714014764 5ustar ggggconstant-defer-6/devel/Singleton/Const.pm0000644000175000017500000000463511256300311016376 0ustar gggg# This was an idea to have a Class::Singleton form with the inherited # ->instance installing a constant sub as the class ->instance, on the first # call. # # The difference is thus in holding the instance in a constant sub as # opposed to the way Class::Singleton does it in a package variable. It has # to build and lookup that variable each time, whereas a constant sub would # be hit directly by the method lookup. On the whole very little between # the two in either time or space ... # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . package Class::Singleton::Const; use strict; use warnings; use Carp; sub instance { my ($class) = @_; my $instance = $class->_new_instance; my $funcname = "${class}::instance"; { no strict 'refs'; no warnings; *$funcname = sub () { $instance }; } # constant.pm optimizes to save a typeglob, but it doesn't allow a # particular package to be given, only the caller() package # require constant; # constant->import ("${class}::instance", $instance); require constant; $_ = $instance; eval "package \Q$class\E; use constant instance => \$_; 1" or die $@; return $instance; } sub _new_instance { my ($class) = @_; croak "Singleton: $class->_new_instance() not defined"; } 1; __END__ # BEGIN { # print $xyz; # eval "no strict"; # print $xyz; # } # package x\;y; package MyClass; our @ISA = ('Class::Singleton::Const'); sub new { my ($class) = @_; return bless {}, $class; } *_new_instance = \&new; package main; print exists(&MyClass::instance),"\n"; print MyClass->instance,"\n"; print exists(&MyClass::instance),"\n"; 1; __END__ our $x = [ 'x' ]; print "$funcname\n"; my $y = $x; # use Data::Dumper; # print Dumper(\*$funcname),"\n"; require Scalar::Util; Scalar::Util::weaken ($x); constant-defer-6/devel/run.pl0000644000175000017500000000360311424406742014157 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; { sub make_subr { return sub { 123 }; } my $x = make_subr(); require Scalar::Util; require Data::Dumper; Scalar::Util::weaken($x); print Data::Dumper->Dump([\$x],['x']); # require Devel::FindRef; # print Devel::FindRef::track(\$x); no warnings 'redefine'; *make_subr = sub {}; print Data::Dumper->Dump([\$x],['x']); sub make_two { my ($a) = @_; return sub { $a }; } $x = make_two(123); my $y = make_two(456); Scalar::Util::weaken($x); #Scalar::Util::weaken($y); print Data::Dumper->Dump([\$x],['x']); print Data::Dumper->Dump([\$y],['y']); exit 0; } { use constant::defer my_ctime => sub { return 123; #require POSIX; #return POSIX::ctime(time()); }; my $orig = \&my_ctime; print my_ctime(),"\n"; my $const = \&my_ctime; print "orig $orig\n"; print "const $const\n"; print "subr ",$constant::defer::DEBUG_LAST_SUBR,"\n"; require Scalar::Util; Scalar::Util::weaken($constant::defer::DEBUG_LAST_SUBR); print "subr ",$constant::defer::DEBUG_LAST_SUBR,"\n"; exit 0; } constant-defer-6/devel/name.pl0000644000175000017500000000265211424406742014276 0ustar gggg#!/usr/bin/perl -w # Copyright 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Sub::Identify; use Data::Dumper; use constant foo => 123; BEGIN { my $symtab = \%main::; print Data::Dumper->Dump([$symtab->{'foo'}], ['foo']); } print "foo ",Sub::Identify::sub_fullname(\&foo),"\n"; BEGIN { my $symtab = \%main::; print Data::Dumper->Dump([$symtab->{'foo'}], ['foo']); } our $exglob = 999; use constant exglob => 123; print "exglob ",Sub::Identify::sub_fullname(\&exglob),"\n"; use constant::defer bar => sub { 456 }; print "bar ",Sub::Identify::sub_fullname(\&bar),"\n"; require Glib; print "FALSE ",Sub::Identify::sub_fullname(\&Glib::FALSE),"\n"; print "MAJOR_VERSION ",Sub::Identify::sub_fullname(\&Glib::MAJOR_VERSION)," ",Glib::MAJOR_VERSION(),"\n"; 1; constant-defer-6/devel/junk/0002755000175000017500000000000012471561714013771 5ustar ggggconstant-defer-6/devel/junk/Attribute-MemoizeToConstant.pm0000644000175000017500000000776011356526020021712 0ustar gggg# no good because Attribute::Handlers doesn't run at the right phase in a # require or eval # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . package Attribute::MemoizeToConstant; use Attribute::Handlers; ## no critic (RequireUseStrict RequireUseWarnings) no strict; no warnings; push @UNIVERSAL::ISA, __PACKAGE__; use constant DEBUG => 0; our $c; my @pending; my $checked = 0; sub MODIFY_CODE_ATTRIBUTES { my ($package, $coderef, @attrs) = @_; if (DEBUG) { print "MemoizeToConstant pending $package $coderef\n"; } push @pending, [$package, $coderef]; if ($checked) { run_pending(); } return grep {$_ ne 'MemoizeToConstant'} @attrs; } CHECK { if (DEBUG) { print "MemoizeToConstant CHECK\n"; } $checked = 1; run_pending(); } sub run_pending { while (@pending) { my ($package, $oldcode) = @{pop @pending}; if (DEBUG) { print " $package $oldcode\n"; } $c = $oldcode; require Scalar::Util; Scalar::Util::weaken ($c); my $found; my $phash = \%{"${package}::"}; foreach my $name (keys %$phash) { my $glob = $phash->{$name}; ref(\$glob) eq 'GLOB' or next; (*{$glob}{CODE} || 0) == $oldcode or next; my $fullname = "${package}::$name"; if (DEBUG) { print " install to $fullname\n"; } *$fullname = sub () { my $value = $oldcode->(@_); *$fullname = sub () { $value }; return $value; }; $found = 1; } $found or warn "MemoizeToConstant func $oldcode not found in $package"; } } 1; __END__ # sub make_func { # return sub () { # my $value = $_[0]oldcode->(@_); # *$sym = sub () { $value }; # return $value; # } # } # use Data::Dumper; # print Dumper(\@_); # # use Data::Dump; # print Data::Dump::dump(\*main::foo); # # my $x = findsym ($package, $coderef); # print "findsym ",Dumper($x); # # no strict; # # my $type = ref($coderef); # Attribute::Handlers holds onto to the original coderef, so it's not freed # when the func is turned into a constant ... package Attribute::MemoizeToConstant; use Attribute::Handlers; use strict; use warnings; our $VERSION = 1; use constant DEBUG => 0; our $c; sub UNIVERSAL::MemoizeToConstant : ATTR(CODE) { my ($package, $typeglob, $oldcode) = @_; $c = $oldcode; Scalar::Util::weaken ($c); if (DEBUG) { print "MemoizeToConstant on '$package' '", *{$typeglob}{NAME}, "' ", $oldcode,"\n"; } no warnings; *$typeglob = sub () { my $value = $oldcode->(@_); *$typeglob = sub () { $value }; return $value; }; } 1; __END__ =head1 NAME Attribute::MemoizeToConstant -- memoize functions to become constants =head1 SYNOPSIS use Attribute::MemoizeToConstant; sub myfunc : MemoizeToConstant { # some long calculation return $x; } =head1 BUGS! Doesn't work when used in a module or file which is loaded by C, C, etc, only from the main program and things brought in C. =head1 DESCRIPTION Attribute C arranges for a function to be memoized so its first call runs the code but it's then transformed into a constant sub (like C) with that first return value. =head1 SEE ALSO =for comment Actually it wants to be attributes(3perl) to avoid attributes(3ncurses), but the formatters complain about that ... L, L, L, L, L =cut constant-defer-6/devel/package-constants.pl0000644000175000017500000000244412467557752017002 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010, 2015 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Package::Constants; use Smart::Comments; { package Foo; use constant PLAIN => 123; use constant::defer C_DEF => sub { 123 }; sub SUBR { 123 } sub SUBRPROT () { 123 } sub SUBRPRINT () { print "hello" } use constant::lexical C_LEX => 123; BEGIN { print "BEGIN\n"; $Package::Constants::DEBUG = 1; my @const = Package::Constants->list('Foo'); ### @const my $func = \&C_LEX; my $prot = prototype($func); ### $func ### $prot } } print "toplevel\n"; my @const = Package::Constants->list('Foo'); ### @const constant-defer-6/devel/import.pl0000644000175000017500000000271411424406742014667 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Data::Dumper; use Scalar::Util; use FindBin; use lib::abs $FindBin::Bin; use MyConstantDeferExport ('my_ctime'); { my $orig = \&my_ctime; my $orig_m = \&MyConstantDeferExport::my_ctime; print my_ctime(),"\n"; print MyConstantDeferExport::my_ctime(),"\n"; my $const = \&my_ctime; my $const_m = \&MyConstantDeferExport::my_ctime; print "orig $orig\n"; print "orig_m $orig_m\n"; print "const $const\n"; print "const_m $const_m\n"; if (defined $constant::defer::DEBUG_LAST_SUBR) { print "subr ",$constant::defer::DEBUG_LAST_SUBR//'undef',"\n"; Scalar::Util::weaken($constant::defer::DEBUG_LAST_SUBR); print "subr ",$constant::defer::DEBUG_LAST_SUBR//'undef',"\n"; } exit 0; } constant-defer-6/devel/Memoize/0002755000175000017500000000000012471561714014427 5ustar ggggconstant-defer-6/devel/Memoize/t-memoize-toconst-2.pl0000644000175000017500000000201111256235500020477 0ustar gggg#!/usr/bin/perl # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Data::Dumper; sub foo { print "foo runs\n"; return (123, 456); } my $got = foo(); print "got $got\n"; print "\n"; sub bar { print "bar runs\n"; return (123, 456); } use Memoize::ToConstant 'bar'; $got = bar(); print "got $got\n"; $got = bar(); print "got $got\n"; exit 0; constant-defer-6/devel/Memoize/t-memoize-toconst.pl0000644000175000017500000000411311256235474020357 0ustar gggg#!/usr/bin/perl # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Data::Dumper; # my $symtab = do { no strict 'refs'; # \%{"${package}::"} }; BEGIN { my $symtab = \%main::; my $basename = 'foo'; print "symtab ",$symtab->{$basename},"\n"; } sub foo { print "foo\n"; return (123, 456); } BEGIN { my $symtab = \%main::; my $basename = 'foo'; print "symtab ",$symtab->{$basename},"\n"; } print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); use Memoize::ToConstant 'foo'; print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); print "foo(): ",scalar(foo()),"\n"; print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); print "foo(): ",scalar(foo()),"\n"; print "prototype: '",prototype(\&foo)//'undef',"'\n"; print Dumper (\&foo); # wantarray # return print "\n"; sub bar { print "bar runs\n"; return (123, 456); } BEGIN { print "\n"; { my $x = bar(); print "bar() x: $x\n"; } print "bar() scalar: ",scalar(bar()),"\n"; } use Memoize::ToConstant 'bar'; print "bar(): ",bar(),"\n"; print "bar(): ",bar(),"\n"; print "\n"; sub quux { print "quux runs\n"; my @x = (123, 456); return @x; } BEGIN { print "\n"; { my $x = quux(); print "quux() x: $x\n"; } print "quux() scalar: ",scalar(quux()),"\n"; print "\n"; } use Memoize::ToConstant 'quux'; print "quux(): ",quux(),"\n"; print "quux(): ",quux(),"\n"; exit 0; constant-defer-6/devel/Memoize/ToConstant.t0000644000175000017500000000670011256235441016704 0ustar gggg#!/usr/bin/perl # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use warnings; use Memoize::ToConstant; use Test::More tests => 22; SKIP: { eval 'use Test::NoWarnings; 1' or skip 'Test::NoWarnings not available', 1; } my $want_version = 1; ok ($Memoize::ToConstant::VERSION >= $want_version, 'VERSION variable'); ok (Memoize::ToConstant->VERSION >= $want_version, 'VERSION class method'); Memoize::ToConstant->VERSION ($want_version); # basic use { my $foo_runs = 0; sub foo { $foo_runs = 1; return 123 } my $orig_code; BEGIN { $orig_code = \&foo; } use Memoize::ToConstant 'foo'; is (foo(), 123, 'foo() first run'); is ($foo_runs, 1, 'foo() first runs code'); require Scalar::Util; Scalar::Util::weaken ($orig_code); is ($orig_code, undef, 'orig foo() code garbage collected'); $foo_runs = 0; is (foo(), 123, 'foo() second run'); is ($foo_runs, 0, 'foo() second doesn\'t run code'); } { my $succeeds = (eval { Memoize::ToConstant->import('nosuchfunc') } ? 1 : 0); is ($succeeds, 0, 'no such func provokes die'); } { my $succeeds = 0; BEGIN { ##no critic (BuiltinFunctions::ProhibitStringyEval) if (eval "use Memoize::ToConstant 'before'; 1") { $succeeds = 1; } } sub before { return 789 } is ($succeeds, 0, 'memoize before defined provokes die'); } { my $runs = 0; sub Some::Non::Package::Place::func { $runs = 1; return 'xyz' } use Memoize::ToConstant 'Some::Non::Package::Place::func'; is (Some::Non::Package::Place::func(), 'xyz', 'explicit package first run'); is ($runs, 1, 'explicit package first run runs code'); $runs = 0; is (Some::Non::Package::Place::func(), 'xyz', 'explicit package second run'); is ($runs, 0, 'explicit package second run doesn\'t run code'); } { my $runs = 0; sub three { $runs = 1; return ('a','b','c') } use Memoize::ToConstant 'three'; is_deeply ([ three() ], [ 'a', 'b', 'c' ], 'three return values first run'); is ($runs, 1, 'three return values first run runs code'); $runs = 0; is_deeply ([ three() ], [ 'a', 'b', 'c' ], 'three return values second run'); is ($runs, 0, 'three return values second run doesn\'t run code'); } { my $runs = 0; sub three_scalar { $runs = 1; return ('a','b','c') } use Memoize::ToConstant 'three_scalar'; my $got = three_scalar(); is ($got, 3, 'three values in scalar context return values first run'); is ($runs, 1, 'three values in scalar context return values first run runs code'); $runs = 0; $got = three_scalar(); is ($got, 3, 'three values in scalar context return values second run'); is ($runs, 0, 'three values in scalar context return values second run doesn\'t run code'); } exit 0; constant-defer-6/devel/Memoize/ToConstant.pm0000644000175000017500000001220711256277661017066 0ustar gggg# This was an idea to post-facto mangle a function to be run-once. # # Giving a name an anon-sub to constant::defer seems easier than making a # named sub and then repeating the name to Memoize::ToConstant. # # (The _run() here is old, it doesn't make the first installed sub become # the constant as well as the replacement ...) # Copyright 2008, 2009 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . package Memoize::ToConstant; use 5.006; use strict; use warnings; use Carp; our $VERSION = 1; # an alias for prammatic use ? # *memoize_to_constant = \&import; sub import { my $caller_package = caller; shift @_; # classname foreach my $arg (@_) { my ($fullname, $package, $basename); if ($arg =~ /(.*)::(.*)/s) { $fullname = $arg; $package = $1; $basename = $2; } else { $package = $caller_package; $basename = $arg; $fullname = "${caller_package}::$arg"; } # can() might let a strange package autoload the given func, though # that'd be pretty unusual my $old = $package->can($basename) || croak "Function $fullname not defined"; # print "ToConstant $arg -- $fullname $package $basename $old\n"; no warnings; no strict 'refs'; *$fullname = sub () { _run($fullname,$old,@_) }; } } sub _run { my $fullname = shift; my $old = shift; # print "ToConstant $fullname $old\n"; my @ret = $old->(@_); no warnings; # no strict 'refs'; if (@ret == 0) { *$fullname = \&_nothing; return; } if (@ret == 1) { # constant.pm has an optimization to make a constant by storing a scalar # into the %Foo::Bar:: hash if there's no typeglob for the name yet. # But that doesn't apply here, there's always a typeglob having wrapped # and converted an existing function. # my $value = $ret[0]; *$fullname = sub () { $value }; return $value; } *$fullname = sub () { @ret }; @ret; } sub _nothing () { } 1; __END__ =head1 NAME Memoize::ToConstant -- memoize functions to become constants =head1 SYNOPSIS sub foo { ... }; use Memoize::ToConstant 'foo'; sub bar { ... }; # or a set of functions at once sub quux { ... }; use Memoize::ToConstant 'bar','quux'; use Memoize::ToConstant 'Some::Other::func'; =head1 DESCRIPTION C modifies given functions so the first call runs normally but then becomes a constant sub like C. The effect is an on-demand calculation of a constant, or once-only run of some code. The same sort of thing can be done with the main C module (see L), but ToConstant doesn't have to keep track of different sets of arguments (there's no arguments) and in particular it can discard the original code after it runs, freeing some memory. =head1 MULTIPLE VALUES For consistency the original function is always run in array context, no matter how the memoized wrapper is called. The kind of constant sub the function becomes then depends on the number of values returned. =over 4 =item * For no values the new sub is an empty C. =item * For one value the new sub is a scalar return C. This is the usual case and can be inlined by subsequently loaded code (ie. code loaded after the first run). =item * For two or more values the new sub is an array return C. This is similar to what C gives and in array context (which is presumably the purpose of multiple values) it returns those multiple results. The only subtle thing to note is that when used in scalar context it means the size of the array, ie. how many values. This happens even if your original function was a list style C which in scalar context would normally mean last value in that list. =back =head1 FUNCTIONS There are no functions as such, everything is accomplished through the C import. =over 4 =item C<< use Memoize::ToConstant 'func' >> =item C<< use Memoize::ToConstant 'Some::Package::func' >> Modify the given C to become a constant after the first call to it. An unqualified name is taken to be in the caller package doing the C. That's the normal case, but a fully qualified name (anything with a C<::>) can be given. In either case the function must be defined before ToConstant is applied, sub foo { ... }; use Memoize::ToConstant 'foo'; # right use Memoize::ToConstant 'bar'; # WRONG! sub bar { ... }; =back =head1 SEE ALSO L, L, L, L, L, L, L, L =cut constant-defer-6/devel/walk.pl0000644000175000017500000000334111424406741014307 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use 5.010; use strict; use warnings; use B; use B::Utils; use Devel::Peek; use Data::Dumper; use constant::defer FOO => sub { 123 }; Dump (\&FOO); my $c = B::svref_2object(\&FOO); say $c; my $op = $c->ROOT; say "op $op"; B::Utils::walkoptree_simple($op, sub { my ($op) = @_; say "walk $op ",$op->name," ",$op->targ; }); __END__ # B::walkoptree($op, 'main::myop'); # sub myop { # my ($op) = @_; # say "myop ",$op; # } exit 0; my $pad = $c->PADLIST; say "pad ",$pad," fill ",$pad->FILL," max ",$pad->MAX; { my $ref = $pad->object_2svref; say "pad ",Dumper(\$ref); } my @pa = $pad->ARRAY; say "pa ",@pa; # $a," fill ",$a->FILL," max ",$a->MAX; foreach my $a (@pa) { say "a ",$a; my @aa = $pad->ARRAY; say " aa ",@aa; # $a," fill ",$a->FILL," max ",$a->MAX; foreach my $b (@aa) { say " ",$b; my $ref = $b->object_2svref; say " ",Dumper(\$ref); my @bb = $b->ARRAY; say " bb ",@bb;< } } exit 0; constant-defer-6/lib/0002755000175000017500000000000012471561714012471 5ustar ggggconstant-defer-6/lib/constant/0002755000175000017500000000000012471561714014322 5ustar ggggconstant-defer-6/lib/constant/defer.pm0000644000175000017500000003363312467567725015770 0ustar gggg# Copyright 2008, 2009, 2010, 2011, 2012, 2015 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . package constant::defer; use strict; use vars '$VERSION'; $VERSION = 6; sub import { my $class = shift; $class->_create_for_package (scalar(caller), @_); } sub _create_for_package { my $class = shift; my $target_package = shift; while (@_) { my $name = shift; if (ref $name eq 'HASH') { unshift @_, %$name; next; } unless (@_) { require Carp; Carp::croak ("Missing value sub for $name"); } my $subr = shift; ### $constant::defer::DEBUG_LAST_SUBR = $subr; my ($fullname, $basename); if ($name =~ /::([^:]*)$/s) { $fullname = $name; $basename = $1; } else { $basename = $name; $fullname = "${target_package}::$name"; } ## print "constant::defer $arg -- $fullname $basename $old\n"; $class->_validate_name ($basename); $class->_create_fullname ($fullname, $subr); } } sub _create_fullname { my ($class, $fullname, $subr) = @_; my $run = sub { unshift @_, $fullname, $subr; goto &_run; }; my $func = sub () { unshift @_, \$run; goto $run; }; no strict 'refs'; *$fullname = $func; ### $constant::defer::DEBUG_LAST_RUNNER = $run; } sub _run { my $fullname = shift; my $subr = shift; my $run_ref = shift; ### print "_run() $fullname $subr\n"; my @ret = &$subr(@_); if (@ret == 1) { # constant.pm has an optimization to make a constant by storing a scalar # value directly into the %{Foo::Bar::} hash if there's no typeglob for # the name yet. But that doesn't apply here, there's always a glob from # having converted a function. # # The function created only has name __ANON__ in its coderef GV (as # fetched by Sub::Identify for instance). This is the same as most # function creating modules, including Memoize.pm. Plain constant.pm # likewise, except when it uses the scalar ref in symbol table # optimization, in that case a later upgrade to a function gets a name. # my $value = $ret[0]; $subr = sub () { $value }; } elsif (@ret == 0) { $subr = \&_nothing; } else { $subr = sub () { @ret }; } $$run_ref = $subr; { no strict 'refs'; local $^W = 0; # no warnings 'redefine'; eval { *$fullname = $subr } or die $@; } goto $subr; } # not as strict as constant.pm sub _validate_name { my ($class, $name) = @_; if ($name =~ m{[()] # no parens like CODE(0x1234) if miscounted args |^[0-9] # no starting with a number |^$ # not empty }x) { require Carp; Carp::croak ("Constant name '$name' is invalid"); } } sub _nothing () { } ## no critic (ProhibitSubroutinePrototypes) 1; __END__ =for stopwords bareword stringizing inline there'd fakery subclassing Ryde multi-value inlined coderef subrs subr =head1 NAME constant::defer -- constant subs with deferred value calculation =for test_synopsis my ($some,$thing,$an,$other); =head1 SYNOPSIS use constant::defer FOO => sub { return $some + $thing; }, BAR => sub { return $an * $other; }; use constant::defer MYOBJ => sub { require My::Class; return My::Class->new_thing; } =head1 DESCRIPTION C creates a subroutine which on the first call runs given code to calculate its value, and on any subsequent calls just returns that value, like a constant. The value code is discarded once run, allowing it to be garbage collected. Deferring a calculation is good if it might take a lot of work or produce a big result but is only needed sometimes or only well into a program run. If it's never needed then the value code never runs. A deferred constant is generally not inlined or folded (see L) since it's not a single scalar value. In the current implementation a deferred constant becomes a plain constant after the first use, so may inline etc in code compiled after that (see L below). See F in the constant-defer source code for a complete sample program. =head2 Uses Here are some typical uses. =over 4 =item * A big value or slow calculation only sometimes needed, use constant::defer SLOWVALUE => sub { long calculation ...; return $result; }; if ($option) { print "s=", SLOWVALUE, "\n"; } =item * A shared object instance created when needed then re-used, use constant::defer FORMATTER => sub { return My::Formatter->new }; if ($something) { FORMATTER()->format ... } =item * The value code might load requisite modules too, again deferring that until actually needed, use constant::defer big => sub { require Some::Big::Module; return Some::Big::Module->create_something(...); }; =item * Once-only setup code can be created with no return value. The code is garbage collected after the first run and becomes a do-nothing. Remember to have an empty or C return value so as not to keep the last expression result alive forever. use constant::defer MY_INIT => sub { many lines of setup code ...; return; }; sub new { MY_INIT(); ... } =back =head1 IMPORTS There are no functions as such, everything works through the C import. =over 4 =item C<< use constant::defer NAME1=>SUB1, NAME2=>SUB2, ...; >> The parameters are name/subroutine pairs. For each one a sub called C is created, running the given C the first time its value is needed. C defaults to the caller's package, or a fully qualified name can be given. Remember that bareword stringizing of C<=E> doesn't act on a fully qualified name, so add quotes in that case. use constant::defer 'Other::Package::BAR' => sub { ... }; For compatibility with the C module a hash of name/sub arguments is accepted too. But C doesn't need this style since there's only ever one thing (a sub) following each name. use constant::defer { FOO => sub { ... }, BAR => sub { ... } }; # works without the hashref too use constant::defer FOO => sub { ... }, BAR => sub { ... }; =back =head1 MULTIPLE VALUES The value sub can return multiple values to make an array style constant sub. use constant::defer NUMS => sub { return ('one', 'two') }; foreach (NUMS) { print $_,"\n"; } The value sub is always run in array context, for consistency, irrespective how the constant is used. The return from the new constant sub is an array style sub () { return @result } If the value sub was a list-style return like C shown above, then this array-style return is slightly different. In scalar context a list return means the last value (like a comma operator), but an array return in scalar context means the number of elements. A multi-value constant won't normally be used in scalar context, so the difference shouldn't arise. The array style is easier for C to implement and is the same as the plain C module does. =head1 ARGUMENTS If the constant is called with arguments then they're passed on to the value sub. This can be good for constants used as object or class methods. Passing anything to plain constants would be unusual. A cute use for a class method style is to make a "singleton" instance of the class. See F in the constant-defer source code for a complete program. package My::Class; use constant::defer INSTANCE => sub { my ($class) = @_; return $class->new }; package main; $obj = My::Class->INSTANCE; Some care might be needed if letting a subclass object become the parent C, though if a program only ever used the subclass then that might in fact be desirable. Subs created by C always have prototype C<()>, ensuring they always parse the same way. The prototype has no effect when called as a method like above, but if you want to make a plain call with arguments then use C<&> to bypass the prototype (see L). &MYCONST ('Some value'); =head1 IMPLEMENTATION Currently C creates a sub under the requested name and when called it replaces that with a new constant sub the same as C would make. This is compact and means that later loaded code might be able to inline it. It's fine to keep a reference to the initial sub and in fact that happens quite normally if importing into another module (with the usual C), or an explicit C<\&foo>, or a C<$package-Ecan('foo')>. The initial sub changes itself to jump to the new constant, it doesn't re-run the value code. The jump is currently done by a C to the new coderef, so it's a touch slower than the new constant sub directly. A spot of XS would no doubt make the difference negligible, perhaps to the point where there'd be no need for a new sub, just have the initial transform itself. If the new form looked enough like a plain constant it might inline in later loaded code. For reference, C (as of its version 0.06) considers C subrs as constants, both before and after the first call which runs the value code. C just looks for prototype S> functions, so any such subr rates as a constant. =head1 OTHER WAYS TO DO IT There's many ways to do "deferred" or "lazy" calculations. =over 4 =item * C makes a function repeat its return. Results are cached against the arguments, so it keeps the original code, whereas C discards after the first run. =item * C and its friends make a create-once Cinstance> method. C can go close with the fakery shown under L above, though without a C to query. =item * C offers some syntactic sugar for redefining the running subroutine, including to a constant. =item * C can create an instance function for a class. It's designed for objects and so doesn't allow 0 or C as the return value. =item * C mangles the code in its caller to put a value as a constant there. The effect is to run a function just once at each caller location, replacing it with the return value, though the function can also choose to constant-ize only sometimes, based on circumstances, arguments, etc. =item * A C<$foo> scalar variable can be rigged up to run code on its first access. C uses a C. C and C use C on an object. C optimizes out the object from C after the first run. C uses XS magic (removed after the first fetch) and some parsing for syntactic sugar. The advantage of a variable is that it interpolates in strings. The disadvantages are it won't inline in later loaded code; bad XS code might bypass the magic; and package variables aren't very friendly when subclassing. =item * C and C rig up an object wrapper to load and create an actual object only when a method is called, dispatching to it and replacing the caller's C<$_[0]>. The advantage is you can pass the wrapper object around, etc, deferring creation to an even later time than a sub or scalar can. =item * C, C and C help make a defer class which transforms lazy stub objects to real ones when a method call is made. A separate defer class is required for each real class. =item * C sets up a run-once code block, but with no particular return value and not discarding the code after run. =item * C and C load code on a class method call such as object creation. They're mainly to defer module loading rather than calculation of a particular value. =item * C and C makes array elements calculated on-demand from a generator function. C does a similar thing for hashes. C hides a function behind a scalar; its laziness is in the arguments which are not evaluated until used. =back =head1 SEE ALSO L, L, L L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L =head1 HOME PAGE http://user42.tuxfamily.org/constant-defer/index.html =head1 COPYRIGHT Copyright 2009, 2010, 2011, 2012, 2015 Kevin Ryde constant-defer 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 3, or (at your option) any later version. constant-defer 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 constant-defer. If not, see . =cut constant-defer-6/t/0002755000175000017500000000000012471561714012166 5ustar ggggconstant-defer-6/t/constant-defer.t0000755000175000017500000002320512467552624015277 0ustar gggg#!/usr/bin/perl -w # Copyright 2008, 2009, 2010, 2011, 2013, 2015 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any later # version. # # constant-defer 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 constant-defer. If not, see . use strict; use constant::defer; use Test; use lib 't'; use MyTestHelpers; MyTestHelpers::nowarnings(); plan tests => 49; sub streq_array { my ($a1, $a2) = @_; while (@$a1 && @$a2) { unless ((! defined $a1->[0] && ! defined $a2->[0]) || (defined $a1->[0] && defined $a2->[0] && $a1->[0] eq $a2->[0])) { return 0; } shift @$a1; shift @$a2; } return (@$a1 == @$a2); } #------------------------------------------------------------------------------ # VERSION { my $want_version = 6; ok ($constant::defer::VERSION, $want_version, 'VERSION variable'); ok (constant::defer->VERSION, $want_version, 'VERSION class method'); ok (eval { constant::defer->VERSION($want_version); 1 }, 1, "VERSION class check $want_version"); my $check_version = $want_version + 1000; ok (! eval { constant::defer->VERSION($check_version); 1 }, 1, "VERSION class check $check_version"); } #------------------------------------------------------------------------------ # plain name my $have_weaken; my $skip_weaken; { my $foo_runs = 0; use constant::defer FOO => sub { $foo_runs++; return 123 }; my $orig_code; $orig_code = \&FOO; ok (FOO, 123, 'FOO first run'); ok ($foo_runs, 1, 'FOO first runs code'); ok (&$orig_code(), 123, 'FOO orig second run'); ok ($foo_runs, 1, "FOO orig second doesn't run code"); $have_weaken = eval { require Scalar::Util; my $x = [ 'hello' ]; Scalar::Util::weaken($x); if (defined $x) { die "Oops, weakening didn't garbage collect"; } 1 }; if (! $have_weaken) { MyTestHelpers::diag ("Scalar::Util::weaken() not available -- ",$@); $skip_weaken = 'due to Scalar::Util::weaken() not available'; } { if ($have_weaken) { Scalar::Util::weaken ($orig_code); } skip ($skip_weaken, ! defined $orig_code, 1, 'orig FOO code garbage collected'); $foo_runs = 0; ok (FOO, 123, 'FOO second run'); ok ($foo_runs, 0, "FOO second doesn't run code"); } } #------------------------------------------------------------------------------ # fully qualified name { my $runs = 0; use constant::defer 'Some::Non::Package::Place::func' => sub { $runs = 1; return 'xyz' }; ok (Some::Non::Package::Place::func(), 'xyz', 'explicit package first run'); ok ($runs, 1, 'explicit package first run runs code'); $runs = 0; ok (Some::Non::Package::Place::func(), 'xyz', 'explicit package second run'); ok ($runs, 0, 'explicit package second run doesn\'t run code'); } #------------------------------------------------------------------------------ # array value { my $runs = 0; use constant::defer THREE => sub { $runs = 1; return ('a','b','c') }; ok (streq_array ([ THREE() ], [ 'a', 'b', 'c' ]), 1, 'THREE return values first run'); ok ($runs, 1, 'THREE return values first run runs code'); $runs = 0; ok (streq_array([ THREE() ], [ 'a', 'b', 'c' ]), 1, 'THREE return values second run'); ok ($runs, 0, 'THREE return values second run doesn\'t run code'); } { my $runs = 0; use constant::defer THREE_SCALAR => sub { $runs = 1; return ('a','b','c') }; my $got = THREE_SCALAR(); ok ($got, 3, 'three values in scalar context return values first run'); ok ($runs, 1, 'three values in scalar context return values first run runs code'); $runs = 0; $got = THREE_SCALAR(); ok ($got, 3, 'three values in scalar context return values second run'); ok ($runs, 0, 'three values in scalar context return values second run doesn\'t run code'); } #------------------------------------------------------------------------------ # multiple names { use constant::defer PAIR_ONE => sub { 123 }, PAIR_TWO => sub { 456 }; ok (PAIR_ONE, 123, 'PAIR_ONE'); ok (PAIR_TWO, 456, 'PAIR_TWO'); } { use constant::defer { HASH_ONE => sub { 123 }, HASH_TWO => sub { 456 } }; ok (HASH_ONE, 123, 'HASH_ONE'); ok (HASH_TWO, 456, 'HASH_TWO'); } { use constant::defer SHASH_ONE => sub { 123 }, { SHASH_TWO => sub { 456 }, SHASH_THREE => sub { 789 } }; ok (SHASH_ONE, 123, 'SHASH_ONE'); ok (SHASH_TWO, 456, 'SHASH_TWO'); ok (SHASH_THREE, 789, 'SHASH_THREE'); } #------------------------------------------------------------------------------ # with can() { my $runs = 0; package MyTestCan; use constant::defer CANNED => sub { $runs++; return 'foo' }; package main; my $func = MyTestCan->can('CANNED'); my $got = &$func(); ok ($got, 'foo', 'through can() - result'); ok ($runs, 1, 'through can() - run once'); $got = &$func(); ok ($got, 'foo', 'through can() - 2nd result'); ok ($runs, 1, 'through can() - 2nd still run once'); } #------------------------------------------------------------------------------ # with Exporter import() { my $runs = 0; package MyTestImport; use vars qw(@ISA @EXPORT); use constant::defer TEST_IMPORT_FOO => sub { $runs++; return 'foo' }; require Exporter; @ISA = ('Exporter'); @EXPORT = ('TEST_IMPORT_FOO'); package main; MyTestImport->import; my $got = TEST_IMPORT_FOO(); ok ($got, 'foo', 'through import - result'); ok ($runs, 1, 'through import - run once'); $got = TEST_IMPORT_FOO(); ok ($got, 'foo', 'through import - 2nd result'); ok ($runs, 1, 'through import - 2nd still run once'); } #------------------------------------------------------------------------------ # gc of supplied $subr after it's been called { my $subr; BEGIN { # crib: anon sub must refer to a lexical or isn't gc'ed, at least in 5.6.0 my $lexical_var = 'gc me'; $subr = sub { return $lexical_var }; } use constant::defer WEAKEN_CONST => $subr; # including when the can() first func is retained # my $cancode = main->can('WEAKEN_CONST'); my @got = WEAKEN_CONST(); ok (streq_array (\@got, ['gc me']), 1, 'WEAKEN_CONST - result'); if ($have_weaken) { Scalar::Util::weaken ($subr); } skip ($skip_weaken, ! defined $subr, 1, 'WEAKEN_CONST - subr now undef'); } { my ($objref, $subr); my $runs = 0; BEGIN { my %obj = (foo => 'bar'); $subr = sub { $runs++; return %obj }; $objref = \%obj; } use constant::defer WEAKEN_OBJRET => $subr; # including when the can() first func is retained # my $cancode = main->can('WEAKEN_OBJRET'); my @got = WEAKEN_OBJRET(); ok (streq_array (\@got, ['foo','bar']), 1, 'WEAKEN_OBJRET - result'); ok ($runs, 1, 'WEAKEN_OBJRET - run once'); if ($have_weaken) { Scalar::Util::weaken ($subr); Scalar::Util::weaken ($objref); } skip ($skip_weaken, ! defined $subr, 1, 'WEAKEN_OBJRET - subr now undef'); skip ($skip_weaken, ! defined $objref, 1, 'WEAKEN_OBJRET - objref now undef'); } #------------------------------------------------------------------------------ # gc of can() after called { use constant::defer CAN_GC => sub { return 'gc me' }; my $cancode = main->can('CAN_GC'); my @got = CAN_GC(); ok (streq_array (\@got, ['gc me']), 1, 'CAN_GC - result'); if ($have_weaken) { Scalar::Util::weaken ($cancode); } skip ($skip_weaken, ! defined $cancode, 1, 'CAN_GC - can() coderef now undef'); } #------------------------------------------------------------------------------ # gc of initial definition after called { use constant::defer INITIAL_GC => sub { return 'gc me' }; my $coderef = \&INITIAL_GC; my @got = INITIAL_GC(); ok (streq_array (\@got, ['gc me']), 1, 'INITIAL_GC - result'); if ($have_weaken) { Scalar::Util::weaken ($coderef); } skip ($skip_weaken, ! defined $coderef, 1, 'INITIAL_GC - saved initial now undef'); } #------------------------------------------------------------------------------ # gc of runner helper after redefine { use constant::defer RUNNER_GC => sub { return 'gc me' }; my $runner; BEGIN { $runner = $constant::defer::DEBUG_LAST_RUNNER; undef $constant::defer::DEBUG_LAST_RUNNER; } if (! $runner) { MyTestHelpers::diag ("DEBUG_LAST_RUNNER not enabled in defer.pm"); } do { local $^W = 0; # no warnings 'redefine'; eval '*RUNNER_GC = sub () { "new value" }; 1'; } or die "Oops, eval error: $@"; if ($have_weaken) { Scalar::Util::weaken ($runner); } skip ($skip_weaken, ! defined $runner, 1, 'RUNNER_GC - now undef'); if ($runner) { require Devel::FindRef; MyTestHelpers::diag (Devel::FindRef::track($runner)); } } exit 0; constant-defer-6/t/MyTestHelpers.pm0000644000175000017500000002474511757337371015314 0ustar gggg# MyTestHelpers.pm -- my shared test script helpers # Copyright 2008, 2009, 2010, 2011, 2012 Kevin Ryde # MyTestHelpers.pm is shared by several distributions. # # MyTestHelpers.pm 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 3, or (at your option) any later # version. # # MyTestHelpers.pm 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 file. If not, see . BEGIN { require 5 } package MyTestHelpers; use strict; use Exporter; use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); # uncomment this to run the ### lines #use Smart::Comments; @ISA = ('Exporter'); @EXPORT_OK = qw(findrefs main_iterations warn_suppress_gtk_icon glib_gtk_versions any_signal_connections nowarnings); %EXPORT_TAGS = (all => \@EXPORT_OK); sub DEBUG { 0 } #----------------------------------------------------------------------------- { my $warning_count; my $stacktraces; my $stacktraces_count = 0; sub nowarnings_handler { my ($msg) = @_; # don't error out for cpan alpha version number warnings unless (defined $msg && $msg =~ /^Argument "[0-9._]+" isn't numeric in numeric gt/) { $warning_count++; if ($stacktraces_count < 3 && eval { require Devel::StackTrace }) { $stacktraces_count++; $stacktraces .= "\n" . Devel::StackTrace->new->as_string() . "\n"; } } warn @_; } sub nowarnings { $SIG{'__WARN__'} = \&nowarnings_handler; } END { if ($warning_count) { MyTestHelpers::diag ("Saw $warning_count warning(s):"); if (defined $stacktraces) { MyTestHelpers::diag ($stacktraces); } else { MyTestHelpers::diag('(Devel::StackTrace not available for backtrace)'); } MyTestHelpers::diag ('Exit code 1 for warnings'); $? = 1; } } } sub diag { if (do { local $@; eval { Test::More->can('diag') }}) { Test::More::diag (@_); } else { my $msg = join('', map {defined($_)?$_:'[undef]'} @_)."\n"; $msg =~ s/^/# /mg; print STDERR $msg; } } sub dump { my ($thing) = @_; if (eval { require Data::Dumper; 1 }) { MyTestHelpers::diag (Data::Dumper::Dumper ($thing)); } else { MyTestHelpers::diag ("Data::Dumper not available"); } } #----------------------------------------------------------------------------- # Test::Weaken and other weaking sub findrefs { my ($obj) = @_; defined $obj or return; require Scalar::Util; if (ref $obj && Scalar::Util::reftype($obj) eq 'HASH') { MyTestHelpers::diag ("Keys: ", join(' ', map {"$_=".(defined $obj->{$_} ? "$obj->{$_}" : '[undef]')} keys %$obj)); } if (eval { require Devel::FindRef }) { MyTestHelpers::diag (Devel::FindRef::track($obj, 8)); } else { MyTestHelpers::diag ("Devel::FindRef not available -- ", $@); } } sub test_weaken_show_leaks { my ($leaks) = @_; $leaks || return; my $unfreed = $leaks->unfreed_proberefs; my $unfreed_count = scalar(@$unfreed); MyTestHelpers::diag ("Test-Weaken leaks $unfreed_count objects"); MyTestHelpers::dump ($leaks); my $proberef; foreach $proberef (@$unfreed) { MyTestHelpers::diag (" unfreed ", $proberef); } foreach $proberef (@$unfreed) { MyTestHelpers::diag ("search ", $proberef); MyTestHelpers::findrefs($proberef); } } #----------------------------------------------------------------------------- # Gtk/Glib helpers # Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do() # if dbus is not running, or something like that. In any case limiting the # iterations is good for test safety. # sub main_iterations { my $count = 0; if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); } while (Gtk2->events_pending) { $count++; Gtk2->main_iteration_do (0); if ($count >= 500) { MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations"); return; } } MyTestHelpers::diag ("main_iterations(): ran $count events/iterations"); } # warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam # from Gtk trying to make you buy the hi-colour icon theme. Eg, # # { # local $SIG{'__WARN__'} = \&MyTestHelpers::warn_suppress_gtk_icon; # $something = SomeThing->new; # } # sub warn_suppress_gtk_icon { my ($message) = @_; unless ($message =~ /Gtk-WARNING.*icon/ || $message =~ /\Qrecently-used.xbel/ ) { warn @_; } } sub glib_gtk_versions { my $gtk1_loaded = Gtk->can('init'); my $gtk2_loaded = Gtk2->can('init'); my $glib_loaded = Glib->can('get_home_dir'); if ($gtk1_loaded) { MyTestHelpers::diag ("Perl-Gtk1 version ",Gtk->VERSION); } if ($gtk2_loaded) { MyTestHelpers::diag ("Perl-Gtk2 version ",Gtk2->VERSION); } if ($glib_loaded) { # when loaded MyTestHelpers::diag ("Perl-Glib version ",Glib->VERSION); MyTestHelpers::diag ("Compiled against Glib version ", Glib::MAJOR_VERSION(), ".", Glib::MINOR_VERSION(), ".", Glib::MICRO_VERSION(), "."); MyTestHelpers::diag ("Running on Glib version ", Glib::major_version(), ".", Glib::minor_version(), ".", Glib::micro_version(), "."); } if ($gtk2_loaded) { MyTestHelpers::diag ("Compiled against Gtk version ", Gtk2::MAJOR_VERSION(), ".", Gtk2::MINOR_VERSION(), ".", Gtk2::MICRO_VERSION(), "."); MyTestHelpers::diag ("Running on Gtk version ", Gtk2::major_version(), ".", Gtk2::minor_version(), ".", Gtk2::micro_version(), "."); } if ($gtk1_loaded) { MyTestHelpers::diag ("Running on Gtk version ", Gtk->major_version(), ".", Gtk->minor_version(), ".", Gtk->micro_version(), "."); } } # Return true if there's any signal handlers connected to $obj. # # Signal IDs are from 1 up, don't pass 0 to signal_handler_is_connected() # since in Glib 2.4.1 it spits out a g_log() error. # sub any_signal_connections { my ($obj) = @_; my @connected = grep {$obj->signal_handler_is_connected ($_)} (1 .. 500); if (@connected) { my $connected = join(',',@connected); MyTestHelpers::diag ("$obj signal handlers connected: $connected"); return $connected; } return undef; } # wait for $signame to be emitted on $widget, with a timeout sub wait_for_event { my ($widget, $signame) = @_; if (DEBUG) { MyTestHelpers::diag ("wait_for_event() $signame on ",$widget); } my $done = 0; my $got_event = 0; my $sig_id = $widget->signal_connect ($signame => sub { if (DEBUG) { MyTestHelpers::diag ("wait_for_event() $signame received"); } $done = 1; return 0; # Gtk2::EVENT_PROPAGATE (new in Gtk2 1.220) }); my $timer_id = Glib::Timeout->add (30_000, # 30 seconds sub { $done = 1; MyTestHelpers::diag ("wait_for_event() oops, timeout waiting for $signame on ",$widget); return 1; # Glib::SOURCE_CONTINUE (new in Glib 1.220) }); if ($widget->can('get_display')) { # display new in Gtk 2.2 $widget->get_display->sync; } else { # in Gtk 2.0 gdk_flush() is a sync actually Gtk2::Gdk->flush; } my $count = 0; while (! $done) { if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); } Gtk2->main_iteration; $count++; } MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n"); $widget->signal_handler_disconnect ($sig_id); Glib::Source->remove ($timer_id); } #----------------------------------------------------------------------------- # X11::Protocol helpers sub X11_chosen_screen_number { my ($X) = @_; my $i; foreach $i (0 .. $#{$X->{'screens'}}) { if ($X->{'screens'}->[$i]->{'root'} == $X->{'root'}) { return $i; } } die "Oops, current screen not found"; } sub X11_server_info { my ($X) = @_; MyTestHelpers::diag(""); MyTestHelpers::diag("X server info"); MyTestHelpers::diag("vendor: ",$X->{'vendor'}); MyTestHelpers::diag("release_number: ",$X->{'release_number'}); MyTestHelpers::diag("protocol_major_version: ",$X->{'protocol_major_version'}); MyTestHelpers::diag("protocol_minor_version: ",$X->{'protocol_minor_version'}); MyTestHelpers::diag("byte_order: ",$X->{'byte_order'}); MyTestHelpers::diag("num screens: ",scalar(@{$X->{'screens'}})); MyTestHelpers::diag("width_in_pixels: ",$X->{'width_in_pixels'}); MyTestHelpers::diag("height_in_pixels: ",$X->{'height_in_pixels'}); MyTestHelpers::diag("width_in_millimeters: ",$X->{'width_in_millimeters'}); MyTestHelpers::diag("height_in_millimeters: ",$X->{'height_in_millimeters'}); MyTestHelpers::diag("root_visual: ",$X->{'root_visual'}); my $visual_info = $X->{'visuals'}->{$X->{'root_visual'}}; MyTestHelpers::diag(" depth: ",$visual_info->{'depth'}); MyTestHelpers::diag(" class: ",$visual_info->{'class'}, ' ', $X->interp('VisualClass', $visual_info->{'class'})); MyTestHelpers::diag(" colormap_entries: ",$visual_info->{'colormap_entries'}); MyTestHelpers::diag(" bits_per_rgb_value: ",$visual_info->{'bits_per_rgb_value'}); MyTestHelpers::diag(" red_mask: ",sprintf('%#X',$visual_info->{'red_mask'})); MyTestHelpers::diag(" green_mask: ",sprintf('%#X',$visual_info->{'green_mask'})); MyTestHelpers::diag(" blue_mask: ",sprintf('%#X',$visual_info->{'blue_mask'})); MyTestHelpers::diag("ima"."ge_byte_order: ",$X->{'ima'.'ge_byte_order'}, ' ', $X->interp('Significance', $X->{'ima'.'ge_byte_order'})); MyTestHelpers::diag("black_pixel: ",sprintf('%#X',$X->{'black_pixel'})); MyTestHelpers::diag("white_pixel: ",sprintf('%#X',$X->{'white_pixel'})); foreach (0 .. $#{$X->{'screens'}}) { if ($X->{'screens'}->[$_]->{'root'} == $X->{'root'}) { MyTestHelpers::diag("chosen screen: $_"); } } MyTestHelpers::diag(""); } 1; __END__ constant-defer-6/README0000644000175000017500000000252511257522730012601 0ustar ggggCopyright 2009 Kevin Ryde This file is part of constant-defer. constant-defer 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 3, or (at your option) any later version. constant-defer 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 constant-defer. If not, see . constant::defer makes subroutines similar to the builtin constant.pm, but with the value calculation deferred until the sub is actually run. use constant::defer FOO => sub { calculate; return $something }; This is handy for big or slow things only needed sometimes, or where at least the pain can be put off the point needed. Lazy or deferred calculations can be hidden behind a scalar variable too. The choice between a sub and a variable is a matter of style or personal preference. Both ways have advantages, see the constant::defer POD for some notes. The constant-defer home page is http://user42.tuxfamily.org/constant-defer/index.html constant-defer-6/META.json0000644000175000017500000000243412471561714013345 0ustar gggg{ "abstract" : "Constant subs with deferred value calculation.", "author" : [ "Kevin Ryde " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690", "license" : [ "gpl_3" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "constant-defer", "no_index" : { "directory" : [ "t", "inc", "devel", "xt" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "perl" : "5", "vars" : "0" } }, "test" : { "requires" : { "Test" : "0", "lib" : "0" }, "suggests" : { "Scalar::Util" : "0" } } }, "release_status" : "stable", "resources" : { "homepage" : "http://user42.tuxfamily.org/constant-defer/index.html", "license" : [ "http://www.gnu.org/licenses/gpl.html" ] }, "version" : "6" } constant-defer-6/META.yml0000644000175000017500000000126712471561714013200 0ustar gggg--- abstract: 'Constant subs with deferred value calculation.' author: - 'Kevin Ryde ' build_requires: ExtUtils::MakeMaker: '0' Test: '0' lib: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690' license: gpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: constant-defer no_index: directory: - t - inc - devel - xt requires: perl: '5' vars: '0' resources: homepage: http://user42.tuxfamily.org/constant-defer/index.html license: http://www.gnu.org/licenses/gpl.html version: '6' constant-defer-6/SIGNATURE0000644000175000017500000000733512471561714013215 0ustar ggggThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.73. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 842745cb706f8f2126506f544492f7a80dbe29b3 COPYING SHA1 31cfdda6317ecd9dd3dfd80ad8ce126d758813aa Changes SHA1 346c0df713070c774753d4ce3359a766f02d3e17 MANIFEST SHA1 d73f6910c2283dca6aa23a5d820950745dcb76f6 MANIFEST.SKIP SHA1 7755b71f002f2095ff04d24601b3421108c22eca META.json SHA1 b37a66188c02ffecdd524ac971ca0fe234e64291 META.yml SHA1 b6d115e5b78512358986fba87d223288f45a9901 Makefile.PL SHA1 16a62183a94aa6d126c0be4a22a28f16b17e8c42 README SHA1 0c1b11273cf9c01e8ccad8cd72fffe0821c9a5d0 debian/changelog SHA1 ac3478d69a3c81fa62e60f5c3696165a4e5e6ac4 debian/compat SHA1 206410a5764d004630d14e5fb6a0f2b139c0a47b debian/control SHA1 98cb9509973a193aa755f28a96ec84677efd33f4 debian/copyright SHA1 91666c26f38fa205050c1273601a58e160160d1c debian/rules SHA1 61652cd1568dcf2614df833eba241755eee34e89 debian/source/format SHA1 7dbe6d7d60aa7d008194241d9ae7d9190c9cf2a4 debian/watch SHA1 51d58edc4faf28e6dadbd6f19796f5f52ef6fbe7 devel/Memoize/ToConstant.pm SHA1 6ba73e607fd311d6fb77332ee61fcb317e7ed92f devel/Memoize/ToConstant.t SHA1 a47696a45185dedbd80dcd43114e08b901c53337 devel/Memoize/t-memoize-toconst-2.pl SHA1 6b881d857b5b9e884dc2bd1b10d2ca587c58c105 devel/Memoize/t-memoize-toconst.pl SHA1 28f9fbc7df6cd5bbecd14377a0046a8687e28d48 devel/MyConstantDeferExport.pm SHA1 7bf6a08cfca4e7ad72ff852815a9bf88edd8c471 devel/Singleton/Const.pm SHA1 d4982d0f3c1fdfe5c13599432a01c9997c370ff0 devel/circular.pl SHA1 616de7e5e1509f674bee0daad7d9f5bc375279f5 devel/constant-lexical.pl SHA1 3e2ebd33b8fa26a030a51327ebe5eefb483652dc devel/import.pl SHA1 30867f46349b0a9de3362880fc1890e42a9386d1 devel/junk/Attribute-MemoizeToConstant.pm SHA1 9febabcfa584162848315b2f81d4fae18a1096f9 devel/name.pl SHA1 b41d4e9cb1880e538e9fcd0f20287d6f9ea67c26 devel/package-constants.pl SHA1 7da963e42e7e0d85c5d291ffb84bd150112d15f6 devel/run.pl SHA1 cc54d877973af513bc1648df4afcb0da86effac7 devel/walk.pl SHA1 965f9ac6922cb150f9f296dffe275a0841ee5266 examples/instance.pl SHA1 09b94c5696f2b0cfd7ef15439a26240185aa78e5 examples/simple.pl SHA1 2c31f38013695c85f0a75eb2c783989978aa298b inc/my_pod2html SHA1 2bf973221f2265a93d12ca25bd82df3c83bf024e lib/constant/defer.pm SHA1 3855de075da37f5bc4e6a5534b2f00cc14872a98 t/MyTestHelpers.pm SHA1 5b2f434cb581437f69881e62291dfeb5a6f0e876 t/constant-defer.t SHA1 f2ceb7bb4bf68bd24728b90918e63d251fd06183 xt/0-META-read.t SHA1 c9e7a47e1f397eb5f46d7e4ef21754d9df76e36e xt/0-Test-ConsistentVersion.t SHA1 d9e7f38a8dcfdb76c56951e4214be8eeda2e2289 xt/0-Test-DistManifest.t SHA1 9496e4a2a2734c7093ab6961900dd7a55800976e xt/0-Test-Pod.t SHA1 083242d959c1a9242c874982e4585872a95bec93 xt/0-Test-Synopsis.t SHA1 63abbc3297914cd38081e95588fd794f9d1f0306 xt/0-Test-YAML-Meta.t SHA1 1cafa4e23b7a691e09161c0927e6920dd663e2ce xt/0-examples-xrefs.t SHA1 7bc810750906ae91a13b16c7bd833dd6e1c9741b xt/0-file-is-part-of.t SHA1 aeb6f41dfae96d04459448f6c3e3dee44691e722 xt/0-no-debug-left-on.t SHA1 d66edcb63ec58cec45a9b1953bb1c1192bc2e4fd xtools/my-check-copyright-years.sh SHA1 b12199bcc70c569ff43f8d8e2ea1c896f587c62f xtools/my-check-spelling.sh SHA1 fa07c8e559adbd1af5ba613e021991b0819fc7ba xtools/my-deb.sh -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iD8DBQFU5uPMLFMCIV9q3ToRArBtAJ96VvzHkysuOKTjrHCAiRvzBOurfgCgkjrn tGEM31WGaSa0wy3R04Hsu7w= =RR8s -----END PGP SIGNATURE----- constant-defer-6/MANIFEST0000644000175000017500000000213412471561714013052 0ustar ggggChanges COPYING debian/changelog debian/compat debian/control debian/copyright debian/rules debian/source/format debian/watch devel/circular.pl devel/constant-lexical.pl devel/import.pl devel/junk/Attribute-MemoizeToConstant.pm devel/Memoize/t-memoize-toconst-2.pl devel/Memoize/t-memoize-toconst.pl devel/Memoize/ToConstant.pm devel/Memoize/ToConstant.t devel/MyConstantDeferExport.pm devel/name.pl devel/package-constants.pl devel/run.pl devel/Singleton/Const.pm devel/walk.pl examples/instance.pl examples/simple.pl inc/my_pod2html lib/constant/defer.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP README SIGNATURE t/constant-defer.t t/MyTestHelpers.pm xt/0-examples-xrefs.t xt/0-file-is-part-of.t xt/0-META-read.t xt/0-no-debug-left-on.t xt/0-Test-ConsistentVersion.t xt/0-Test-DistManifest.t xt/0-Test-Pod.t xt/0-Test-Synopsis.t xt/0-Test-YAML-Meta.t xtools/my-check-copyright-years.sh xtools/my-check-spelling.sh xtools/my-deb.sh META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) constant-defer-6/MANIFEST.SKIP0000644000175000017500000000604012241340502013600 0ustar gggg#!/usr/bin/perl # MANIFEST.SKIP -- Kevin's various excluded files # Copyright 2008, 2009, 2010, 2011, 2012, 2013 Kevin Ryde # This file is shared among several distributions. # # This file 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 3, or (at your option) # any later version. # # This file 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 file. If not, see . # cf. /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP # emacs backups ~$ # emacs locks (^|/)\.# # emacs autosave (^|/)# # own distdir ^[A-Za-z][A-Za-z0-9-_]*-\d+/ # own dist files \.tar$ \.tar\.gz$ \.deb$ # ExtUtils::MakeMaker leaving Makefile.old # and "myman" leaving MANIFEST.old \.old$ # ExtUtils::MakeMaker "metafile" rule temporary, left behind if interrupted ^META_new\.yml$ # built - MakeMaker ^Makefile$ ^blib ^pm_to_blib ^TAGS$ # MakeMaker 6.18 to 6.25, apparently ^blibdirs\.ts$ # msdos compiler output stuff using gcc, # "XSFILENAME.def" extension, and others fixed names it seems \.def$ ^dll\.base$ ^dll\.exp$ # msdos compiler stuff using ms c \.pdb$ # built - recent Module::Build nonsense ^MYMETA\.yml$ # built - something recent ExtUtils::MakeMaker ^MYMETA\.json$ # built - cdbs and debhelper ^debian/stamp- ^debian/.*\.log$ # built - texinfo.tex temporaries \.(aux|cp|cps|fn|fns|ky|log|pg|toc|tp|tps|vr)$ # built - PGF temporary \.pgf$ # tex or latex output, not distributed for now \.(dvi|pdf|ps)$ # toplevel .c files built from .xs ^[^/]+\.c$ # built .o compiled and .bs from .xs \.o$ \.obj$ \.bs$ # #(^|/)[A-Z][A-Za-z0-9_]*\.c$ #/[^Z])[^/]+\.c$ # built - configury ^a\.out$ ^conftest ^config\.h$ ^myconfig\.h$ # built - toplevel html pages ^[a-zA-Z][^./]+\.html$ # inc/MyMakefileExtras.pm "diff-prev" ^diff\.tmp # inc/MyMakefileExtras.pm "lintian-source" ^temp-lintian # various testing ^tempfile\.png$ ^tempfile \.tmp$ # my dists ^dist-deb ^up$ ^c$ # special case p..ulp test build stuff devel/h2xs/TestConstFoo/ # special case various executables ^devel/exe-[^/.]+$ # special case mall executables ^devel/hblk$ ^devel/mallopt$ ^devel/mallstats$ ^devel/malltrim$ # special case fli executables ^devel/mmap-multi$ # special case widget-bits executables ^devel/grandom$ ^devel/grandom-[a-z]+$ # special case widget-cursor executables ^devel/invisible-blank$ # special case x'or executables ^devel/gtk-gc-colour$ # special case combo executables ^devel/toolbutton-overflow-leak$ # special case xpother executables ^devel/encode-all$ ^devel/encode-dump$ ^devel/Encode-X11-xlib$ ^devel/Encode-X11-xlib2$ # special case xpother samples ^devel/encode.*\.ctext$ ^devel/encode.*\.utf8$ # special htmlext environs ^test-dist/ \.junk$ \.bak$ ^backup ^misc ^maybe ^samples ^samp ^formats constant-defer-6/debian/0002755000175000017500000000000012471561714013145 5ustar ggggconstant-defer-6/debian/control0000644000175000017500000000302112421373467014543 0ustar gggg# Copyright 2009, 2010, 2011, 2012, 2013, 2014 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or # (at your option) any later version. # # constant-defer 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 constant-defer. If not, see . # Build-Depends could have the "maximum_tests" modules from META.yml # for more tests, but they're optional author tests really and would # just make the build tools drag in more stuff. Source: libconstant-defer-perl Section: perl Priority: optional Build-Depends: cdbs, debhelper (>= 5), libtest-more-perl | perl (>= 5.6.2) Maintainer: Kevin Ryde Standards-Version: 3.9.6 Homepage: http://user42.tuxfamily.org/constant-defer/index.html Bugs: mailto:user42_kevin@yahoo.com.au Package: libconstant-defer-perl Architecture: all Depends: perl, ${perl:Depends}, ${misc:Depends} Description: Constant subs with deferred value calculation constant::defer creates constants like constant.pm, but with the value calculated only on the first call. This can save work for values only needed sometimes. constant-defer-6/debian/watch0000644000175000017500000000171411255534010014163 0ustar gggg# Web site version watch, for devscripts uscan program. # Copyright 2009 Kevin Ryde # # This file is part of constant-defer. # # constant-defer 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 3, or # (at your option) any later version. # # constant-defer 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 constant-defer. If not, see . # Crib notes: # "man uscan" describes the format. # test with: uscan --report --verbose --watchfile=debian/watch version=3 http://user42.tuxfamily.org/constant-defer/index.html \ .*/constant-defer-([0-9]+)\.tar\.gz constant-defer-6/debian/source/0002755000175000017500000000000012471561714014445 5ustar ggggconstant-defer-6/debian/source/format0000644000175000017500000000000411357715142015646 0ustar gggg1.0 constant-defer-6/debian/compat0000644000175000017500000000000111255532716014337 0ustar gggg5constant-defer-6/debian/copyright0000644000175000017500000000054012467552626015104 0ustar ggggconstant-defer is Copyright 2009, 2010, 2011, 2015 Kevin Ryde constant-defer is licensed under the GNU General Public License GPL version 3 or at your option any later version. The complete text of GPL version 3 is in the file /usr/share/common-licenses/GPL-3 The program home page is http://user42.tuxfamily.org/constant-defer/index.html constant-defer-6/debian/changelog0000644000175000017500000000023112467552626015020 0ustar gggglibconstant-defer-perl (6-0.1) unstable; urgency=low * Packaged version. -- Kevin Ryde Sat, 14 Feb 2015 15:56:45 +1100 constant-defer-6/debian/rules0000755000175000017500000000155312374741320014222 0ustar gggg#!/usr/bin/make -f # Copyright 2009, 2014 Kevin Ryde # This file is part of constant-defer. # # constant-defer 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 3, or (at your option) any # later version. # # constant-defer 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 constant-defer. If not, see . include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/perl-makemaker.mk DEB_INSTALL_EXAMPLES_libconstant-defer-perl = examples/*