Class-Singleton-1.6/0000755000104000244210000000000013761651117016443 5ustar AdministratorsDomain UsersClass-Singleton-1.6/Artistic0000644000104000244210000001426113761651117020154 0ustar AdministratorsDomain Users The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Class-Singleton-1.6/Changes0000644000104000244210000000444713761651117017747 0ustar AdministratorsDomain UsersRevision history for Perl distribution Class-Singleton 1.6 2020-12-02 - Fixed confusing Changes entry about Perl's licensing terms. [, CPAN RT#132843] - Added optional Changes testing (skipped unless AUTHOR_TESTING). - Reformatted Changes file as per CPAN::Changes::Spec. - Added optional POD coverage testing (skipped unless AUTHOR_TESTING). - Added optional Perl::Critic testing (skipped unless AUTHOR_TESTING). - Made code Perl::Critic clean. - Added optional POD testing (skipped unless AUTHOR_TESTING). - Included GitHub repository URLs in metadata now that source code has been uploaded to GitHub (as of version 1.5). - Included META.json file in addition to META.yml. - Set minimum required ExtUtils::MakeMaker version to 6.64 to ensure that all parameters used are supported, to save jumping through hoops to support earlier versions. (This should not be a problem since ExtUtils::MakeMaker 6.64 is easily installed into Perl 5.8.1 and above, that being the whole point of the new choice of minimum supported Perl version.) - Set minimum required Perl version to 5.8.1. This is in line with the minimum requirement of the "Perl Toolchain". - Corrected typo in a comment. [, CPAN RT#86336] 1.5 2014-11-07 - Work around global destruction order issue. [Craig Manley , CPAN RT#23568/68526] 1.4 2007-09-28 - Added the has_instance() method to return an existing instance without creating a new one. - General cleanup of code, documentation and tests. - Changed licence from Perl Artistic to the same terms as Perl itself (i.e. Artistic 1.0 or GPL v1+). 1.03 1999-01-19 - Incorporated patches from Andreas Koenig to inline calculation of $instance variable. This results in a speedup of around 35%. - Added _new_instance() constructor which is called the first time _instance() is called. This can be overloaded in derived classes to provide more specific object initialisation. - Updated documentation accordingly. 1.02 1998-04-16 - Fixed minor typos and corrected example in documentation. 1.01 1998-02-10 - Minor documentation changes 1.00 1998-02-10 - Initial revision Class-Singleton-1.6/Copying0000644000104000244210000003053013761651117017777 0ustar AdministratorsDomain Users GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! Class-Singleton-1.6/INSTALL0000644000104000244210000000124113761651117017472 0ustar AdministratorsDomain UsersPREREQUISITES Perl Perl version 5.8.1 or later. The latest version of Perl is available from https://www.perl.com/. Perl Modules There are no non-standard Perl modules required by this module. INSTALLATION To install this module, cd to the directory that contains this INSTALL file and type the following: perl Makefile.PL make make test make install Use the appropriate program name instead of "make" in the above commands if your perl was built with a different make program. To determine which make program was used to build your perl type the following: perl -V:make Class-Singleton-1.6/lib/0000755000104000244210000000000013761651104017205 5ustar AdministratorsDomain UsersClass-Singleton-1.6/lib/Class/0000755000104000244210000000000013761651117020256 5ustar AdministratorsDomain UsersClass-Singleton-1.6/lib/Class/Singleton.pm0000644000104000244210000003055513761651117022566 0ustar AdministratorsDomain Users#============================================================================ # # Class::Singleton.pm # # Implementation of a "singleton" module which ensures that a class has # only one instance and provides global access to it. For a description # of the Singleton class, see "Design Patterns", Gamma et al, Addison- # Wesley, 1995, ISBN 0-201-63361-2 # # Written by Andy Wardley # # Copyright (C) 1998 Canon Research Centre Europe Ltd. # Copyright (C) 1998-2008 Andy Wardley. All rights reserved. # Copyright (C) 2014 Steve Hay. All rights reserved. # # This module is free software; you can redistribute it and/or modify it under # the same terms as Perl itself, i.e. under the terms of either the GNU General # Public License or the Artistic License, as specified in the F file. # #============================================================================ package Class::Singleton; use 5.008001; use strict; use warnings; our $VERSION = 1.6; my %_INSTANCES = (); #======================================================================== # # instance() # # Module constructor. Creates an Class::Singleton (or derived) instance # if one doesn't already exist. The instance reference is stored in the # %_INSTANCES hash of the Class::Singleton package. The impact of this is # that you can create any number of classes derived from Class::Singleton # and create a single instance of each one. If the instance reference # was stored in a scalar $_INSTANCE variable, you could only instantiate # *ONE* object of *ANY* class derived from Class::Singleton. The first # time the instance is created, the _new_instance() constructor is called # which simply returns a reference to a blessed hash. This can be # overloaded for custom constructors. Any additional parameters passed to # instance() are forwarded to _new_instance(). # # Returns a reference to the existing, or a newly created Class::Singleton # object. If the _new_instance() method returns an undefined value # then the constructer is deemed to have failed. # #======================================================================== sub instance { my $class = shift; # already got an object return $class if ref $class; # we store the instance against the $class key of %_INSTANCES my $instance = $_INSTANCES{$class}; unless(defined $instance) { $_INSTANCES{$class} = $instance = $class->_new_instance(@_); } return $instance; } #======================================================================= # has_instance() # # Public method to return the current instance if it exists. #======================================================================= sub has_instance { my $class = shift; $class = ref $class || $class; return $_INSTANCES{$class}; } #======================================================================== # _new_instance(...) # # Simple constructor which returns a hash reference blessed into the # current class. May be overloaded to create non-hash objects or # handle any specific initialisation required. #======================================================================== sub _new_instance { my $class = shift; my %args = @_ && ref $_[0] eq 'HASH' ? %{ $_[0] } : @_; bless { %args }, $class; } #======================================================================== # END() # # END block to explicitly destroy all Class::Singleton objects since # destruction order at program exit is not predictable. See CPAN RT # bugs #23568 and #68526 for examples of what can go wrong without this. #======================================================================== END { # dereferences and causes orderly destruction of all instances undef(%_INSTANCES); } 1; __END__ =head1 NAME Class::Singleton - Implementation of a "Singleton" class =head1 SYNOPSIS use Class::Singleton; my $one = Class::Singleton->instance(); # returns a new instance my $two = Class::Singleton->instance(); # returns same instance =head1 DESCRIPTION This is the C module. A Singleton describes an object class that can have only one instance in any system. An example of a Singleton might be a print spooler or system registry. This module implements a Singleton class from which other classes can be derived. By itself, the C module does very little other than manage the instantiation of a single object. In deriving a class from C, your module will inherit the Singleton instantiation method and can implement whatever specific functionality is required. For a description and discussion of the Singleton class, see "Design Patterns", Gamma et al, Addison-Wesley, 1995, ISBN 0-201-63361-2. =head2 Using the Class::Singleton Module To import and use the C module the following line should appear in your Perl program: use Class::Singleton; The L method is used to create a new C instance, or return a reference to an existing instance. Using this method, it is only possible to have a single instance of the class in any system. my $highlander = Class::Singleton->instance(); Assuming that no C object currently exists, this first call to L will create a new C and return a reference to it. Future invocations of L will return the same reference. my $macleod = Class::Singleton->instance(); In the above example, both C<$highlander> and C<$macleod> contain the same reference to a C instance. There can be only one. =head2 Deriving Singleton Classes A module class may be derived from C and will inherit the L method that correctly instantiates only one object. package PrintSpooler; use base 'Class::Singleton'; # derived class specific code sub submit_job { ... } sub cancel_job { ... } The C class defined above could be used as follows: use PrintSpooler; my $spooler = PrintSpooler->instance(); $spooler->submit_job(...); The L method calls the L<_new_instance()> constructor method the first and only time a new instance is created. All parameters passed to the L method are forwarded to L<_new_instance()>. In the base class the L<_new_instance()> method returns a blessed reference to a hash array containing any arguments passed as either a hash reference or list of named parameters. package MyConfig; use base 'Class::Singleton'; sub foo { shift->{ foo }; } sub bar { shift->{ bar }; } package main; # either: hash reference of named parameters my $config = MyConfig->instance({ foo => 10, bar => 20 }); # or: list of named parameters my $config = MyConfig->instance( foo => 10, bar => 20 ); print $config->foo(); # 10 print $config->bar(); # 20 Derived classes may redefine the L<_new_instance()> method to provide more specific object initialisation or change the underlying object type (to a list reference, for example). package MyApp::Database; use base 'Class::Singleton'; use DBI; # this only gets called the first time instance() is called sub _new_instance { my $class = shift; my $self = bless { }, $class; my $db = shift || "myappdb"; my $host = shift || "localhost"; $self->{ DB } = DBI->connect("DBI:mSQL:$db:$host") || die "Cannot connect to database: $DBI::errstr"; # any other initialisation... return $self; } The above example might be used as follows: use MyApp::Database; # first use - database gets initialised my $database = MyApp::Database->instance(); Some time later on in a module far, far away... package MyApp::FooBar use MyApp::Database; # this FooBar object needs access to the database; the Singleton # approach gives a nice wrapper around global variables. sub new { my $class = shift; bless { database => MyApp::Database->instance(), }, $class; } The C L method uses a private hash to store a reference to any existing instance of the object, keyed against the derived class package name. This allows different classes to be derived from C that can co-exist in the same system, while still allowing only one instance of any one class to exist. For example, it would be possible to derive both 'C' and 'C' from C and have a single instance of I in a system, rather than a single instance of I. You can use the L method to find out if a particular class already has an instance defined. A reference to the instance is returned or C if none is currently defined. my $instance = MyApp::Database->has_instance() || warn "No instance is defined yet"; =head2 Methods =over 4 =item instance() This method is called to return a current object instance or create a new one by calling L<_new_instance()>. =item has_instance() This method returns a reference to any existing instance or C if none is defined. my $testing = MySingleton1->has_instance() || warn "No instance defined for MySingleton1"; =item _new_instance() This "private" method is called by L to create a new object instance if one doesn't already exist. It is not intended to be called directly (although there's nothing to stop you from calling it if you're really determined to do so). It creates a blessed hash reference containing any arguments passed to the method as either a hash reference or list of named parameters. # either: hash reference of named parameters my $example1 = MySingleton1->new({ pi => 3.14, e => 2.718 }); # or: list of named parameters my $example2 = MySingleton2->new( pi => 3.14, e => 2.718 ); It is important to remember that the L method will I call the I<_new_instance()> method once, so any arguments you pass may be silently ignored if an instance already exists. You can use the L method to determine if an instance is already defined. =back =head1 EXPORTS I. =head1 KNOWN BUGS I. =head1 FEEDBACK Patches, bug reports, suggestions or any other feedback is welcome. Patches can be sent as GitHub pull requests at L. Bug reports and suggestions can be made on the CPAN Request Tracker at L. Currently active requests on the CPAN Request Tracker can be viewed at L. Please test this distribution. See CPAN Testers Reports at L for details of how to get involved. Previous test results on CPAN Testers Reports can be viewed at L. Please rate this distribution on CPAN Ratings at L. =head1 AVAILABILITY The latest version of this module is available from CPAN (see L for details) at L or L or L. The latest source code is available from GitHub at L. =head1 INSTALLATION See the F file. =head1 AUTHOR Andy Wardley ELE L. Thanks to Andreas Koenig for providing some significant speedup patches and other ideas. Steve Hay ELE is now maintaining Class::Singleton as of version 1.5. =head1 COPYRIGHT Copyright (C) 1998 Canon Research Centre Europe Ltd. Copyright (C) 1998-2008 Andy Wardley. All rights reserved. Copyright (C) 2014, 2020 Steve Hay. All rights reserved. =head1 LICENCE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e. under the terms of either the GNU General Public License or the Artistic License, as specified in the F file. =head1 VERSION Version 1.6 =head1 DATE 02 Dec 2020 =head1 HISTORY See the F file. =cut Class-Singleton-1.6/LICENCE0000644000104000244210000000223413761651117017431 0ustar AdministratorsDomain UsersThis distribution is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version; or b) the "Artistic License" which comes with this distribution. This distribution 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 either the GNU General Public License or the Artistic License for more details. You should have received a copy of the GNU General Public License along with this distribution in the file named "Copying". If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit their web page on the internet at https://www.gnu.org/copyleft/gpl.html or the Perl web page at https://dev.perl.org/licenses/gpl1.html. You should also have received a copy of the Artistic License with this distribution, in the file named "Artistic". If not, visit the Perl web page on the internet at https://dev.perl.org/licenses/artistic.html. Class-Singleton-1.6/Makefile.PL0000644000104000244210000000725313761651117020424 0ustar AdministratorsDomain Users#!perl #=============================================================================== # # Makefile.PL # # DESCRIPTION # Makefile creation script. # # COPYRIGHT # Copyright (C) 2014-2015, 2020 Steve Hay. All rights reserved. # # LICENCE # This script is free software; you can redistribute it and/or modify it under # the same terms as Perl itself, i.e. under the terms of either the GNU # General Public License or the Artistic License, as specified in the LICENCE # file. # #=============================================================================== use 5.008001; use strict; use warnings; use ExtUtils::MakeMaker 6.64; use ExtUtils::MakeMaker qw(WriteMakefile); #=============================================================================== # MAIN PROGRAM #=============================================================================== MAIN: { WriteMakefile( NAME => 'Class::Singleton', ABSTRACT_FROM => 'lib/Class/Singleton.pm', AUTHOR => 'Andy Wardley , Steve Hay ', LICENSE => 'perl_5', VERSION_FROM => 'lib/Class/Singleton.pm', META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', web => 'https://github.com/steve-m-hay/Class-Singleton' } }, optional_features => { changestest => { description => 'Changes testing', prereqs => { test => { requires => { 'Test::CPAN::Changes' => '0' } } } }, critictest => { description => 'Perl::Critic testing', prereqs => { test => { requires => { 'Test::Perl::Critic' => '0' } } } }, podtest => { description => 'POD testing', prereqs => { test => { requires => { 'Test::Pod' => '1.00' } } } }, podcoveragetest => { description => 'POD coverage testing', prereqs => { test => { requires => { 'Test::Pod::Coverage' => '0.08' } } } } } }, MIN_PERL_VERSION => '5.008001', CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '6.64', 'perl' => '5.008001', 'strict' => '0', 'warnings' => '0' }, TEST_REQUIRES => { 'Test::More' => '0', 'base' => '0' }, PREREQ_PM => { 'strict' => '0', 'warnings' => '0' }, dist => { PREOP => 'find $(DISTVNAME) -type d -print|xargs chmod 0755 && ' . 'find $(DISTVNAME) -type f -print|xargs chmod 0644', TO_UNIX => 'find $(DISTVNAME) -type f -print|xargs dos2unix' } ); } #=============================================================================== Class-Singleton-1.6/MANIFEST0000644000104000244210000000215513761651117017577 0ustar AdministratorsDomain UsersArtistic The "Artistic License" Changes Differences from previous version Copying The GNU General Public License INSTALL Detailed installation instructions lib/Class/Singleton.pm Class::Singleton Perl module LICENCE The Licence Makefile.PL Makefile writer MANIFEST This list of files MANIFEST.SKIP Manifest skip specs README The Instructions t/changes.t See if Changes file format is OK t/critic.t See if coding style is OK t/pod.t See if POD is OK t/pod_coverage.t See if POD coverage is OK t/singleton.t Test script META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Class-Singleton-1.6/MANIFEST.SKIP0000644000104000244210000000044513761651117020344 0ustar AdministratorsDomain Users# Source control system files ^\.git/ ^\.gitignore$ # Files generated by Makefile.PL ^Makefile$ ^MYMETA\.json$ ^MYMETA\.yml$ # Files generated by *make ^blib/ ^pm_to_blib$ # Files generated by *make clean ^Makefile\.old$ # Files generated by *make dist ^Class-Singleton-\d\.\d\d\.tar\.gz$ Class-Singleton-1.6/META.json0000644000104000244210000000451513761651117020071 0ustar AdministratorsDomain Users{ "abstract" : "Implementation of a \"Singleton\" class ", "author" : [ "Andy Wardley , Steve Hay " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Class-Singleton", "no_index" : { "directory" : [ "t", "inc" ] }, "optional_features" : { "changestest" : { "description" : "Changes testing", "prereqs" : { "test" : { "requires" : { "Test::CPAN::Changes" : "0" } } } }, "critictest" : { "description" : "Perl::Critic testing", "prereqs" : { "test" : { "requires" : { "Test::Perl::Critic" : "0" } } } }, "podcoveragetest" : { "description" : "POD coverage testing", "prereqs" : { "test" : { "requires" : { "Test::Pod::Coverage" : "0.08" } } } }, "podtest" : { "description" : "POD testing", "prereqs" : { "test" : { "requires" : { "Test::Pod" : "1.00" } } } } }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.64", "perl" : "5.008001", "strict" : "0", "warnings" : "0" } }, "runtime" : { "requires" : { "perl" : "5.008001", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0", "base" : "0" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://github.com/steve-m-hay/Class-Singleton" } }, "version" : 1.6, "x_serialization_backend" : "JSON::PP version 4.02" } Class-Singleton-1.6/META.yml0000644000104000244210000000175013761651117017717 0ustar AdministratorsDomain Users--- abstract: 'Implementation of a "Singleton" class ' author: - 'Andy Wardley , Steve Hay ' build_requires: ExtUtils::MakeMaker: '0' Test::More: '0' base: '0' configure_requires: ExtUtils::MakeMaker: '6.64' perl: '5.008001' strict: '0' warnings: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Class-Singleton no_index: directory: - t - inc optional_features: changestest: description: 'Changes testing' critictest: description: 'Perl::Critic testing' podcoveragetest: description: 'POD coverage testing' podtest: description: 'POD testing' requires: perl: '5.008001' strict: '0' warnings: '0' resources: repository: https://github.com/steve-m-hay/Class-Singleton version: 1.6 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Class-Singleton-1.6/README0000644000104000244210000000247413761651117017332 0ustar AdministratorsDomain UsersNAME Class::Singleton - Implementation of a "Singleton" class SYNOPSIS use Class::Singleton; my $one = Class::Singleton->instance(); # returns a new instance my $two = Class::Singleton->instance(); # returns same instance DESCRIPTION This is the Class::Singleton module. A Singleton describes an object class that can have only one instance in any system. An example of a Singleton might be a print spooler or system registry. This module implements a Singleton class from which other classes can be derived. By itself, the Class::Singleton module does very little other than manage the instantiation of a single object. In deriving a class from Class::Singleton, your module will inherit the Singleton instantiation method and can implement whatever specific functionality is required. INSTALLATION See the INSTALL file. COPYRIGHT Copyright (C) 1998 Canon Research Centre Europe Ltd. Copyright (C) 1998-2008 Andy Wardley. All rights reserved. Copyright (C) 2014, 2020 Steve Hay. All rights reserved. LICENCE This distribution is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e. under the terms of either the GNU General Public License or the Artistic License, as specified in the LICENCE file. Class-Singleton-1.6/t/0000755000104000244210000000000013761651117016706 5ustar AdministratorsDomain UsersClass-Singleton-1.6/t/changes.t0000644000104000244210000000232513761651117020505 0ustar AdministratorsDomain Users#!perl #=============================================================================== # # t/changes.t # # DESCRIPTION # Test script to check CPAN::Changes conformance. # # COPYRIGHT # Copyright (C) 2014 Steve Hay. All rights reserved. # # LICENCE # This script is free software; you can redistribute it and/or modify it under # the same terms as Perl itself, i.e. under the terms of either the GNU # General Public License or the Artistic License, as specified in the LICENCE # file. # #=============================================================================== use 5.008001; use strict; use warnings; use Test::More; #=============================================================================== # MAIN PROGRAM #=============================================================================== MAIN: { plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING}; my $ok = eval { require Test::CPAN::Changes; Test::CPAN::Changes->import(); 1; }; if (not $ok) { plan skip_all => 'Test::CPAN::Changes required to test Changes'; } else { changes_ok(); } } #=============================================================================== Class-Singleton-1.6/t/critic.t0000644000104000244210000000235613761651117020356 0ustar AdministratorsDomain Users#!perl #=============================================================================== # # t/critic.t # # DESCRIPTION # Test script to check Perl::Critic conformance. # # COPYRIGHT # Copyright (C) 2014 Steve Hay. All rights reserved. # # LICENCE # This script is free software; you can redistribute it and/or modify it under # the same terms as Perl itself, i.e. under the terms of either the GNU # General Public License or the Artistic License, as specified in the LICENCE # file. # #=============================================================================== use 5.008001; use strict; use warnings; use Test::More; #=============================================================================== # MAIN PROGRAM #=============================================================================== MAIN: { plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING}; my $ok = eval { require Test::Perl::Critic; Test::Perl::Critic->import(-profile => ''); 1; }; if (not $ok) { plan skip_all => 'Test::Perl::Critic required to test with Perl::Critic'; } else { all_critic_ok('.'); } } #=============================================================================== Class-Singleton-1.6/t/pod.t0000644000104000244210000000243013761651117017654 0ustar AdministratorsDomain Users#!perl #=============================================================================== # # t/pod.t # # DESCRIPTION # Test script to check POD. # # COPYRIGHT # Copyright (C) 2014 Steve Hay. All rights reserved. # # LICENCE # This script is free software; you can redistribute it and/or modify it under # the same terms as Perl itself, i.e. under the terms of either the GNU # General Public License or the Artistic License, as specified in the LICENCE # file. # #=============================================================================== use 5.008001; use strict; use warnings; use Test::More; #=============================================================================== # MAIN PROGRAM #=============================================================================== MAIN: { plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING}; my $ok = eval { require Test::Pod; Test::Pod->import(); 1; }; if (not $ok) { plan skip_all => 'Test::Pod required to test POD'; } elsif ($Test::Pod::VERSION < 1.00) { plan skip_all => 'Test::Pod 1.00 or higher required to test POD'; } else { all_pod_files_ok(); } } #=============================================================================== Class-Singleton-1.6/t/pod_coverage.t0000644000104000244210000000256113761651117021534 0ustar AdministratorsDomain Users#!perl #=============================================================================== # # t/pod_coverage.t # # DESCRIPTION # Test script to check POD coverage. # # COPYRIGHT # Copyright (C) 2014 Steve Hay. All rights reserved. # # LICENCE # This script is free software; you can redistribute it and/or modify it under # the same terms as Perl itself, i.e. under the terms of either the GNU # General Public License or the Artistic License, as specified in the LICENCE # file. # #=============================================================================== use 5.008001; use strict; use warnings; use Test::More; #=============================================================================== # MAIN PROGRAM #=============================================================================== MAIN: { plan skip_all => 'Author testing only' unless $ENV{AUTHOR_TESTING}; my $ok = eval { require Test::Pod::Coverage; Test::Pod::Coverage->import(); 1; }; if (not $ok) { plan skip_all => 'Test::Pod::Coverage required to test POD coverage'; } elsif ($Test::Pod::Coverage::VERSION < 0.08) { plan skip_all => 'Test::Pod::Coverage 0.08 or higher required to test POD coverage'; } else { all_pod_coverage_ok(); } } #=============================================================================== Class-Singleton-1.6/t/singleton.t0000644000104000244210000001330113761651117021073 0ustar AdministratorsDomain Users# # Class::Singleton test script # # Andy Wardley # use 5.008001; use strict; use warnings; use Test::More tests => 29; use Class::Singleton; ## no critic (Modules::RequireFilenameMatchesPackage) # the final test is run by a destructor which is called after Test::Builder # would normally print the test summary, so we disable that Test::More->builder->no_ending(1); ok(1, 'loaded Class::Singleton'); #------------------------------------------------------------------------ # define 'DerivedSingleton', a class derived from Class::Singleton #------------------------------------------------------------------------ package DerivedSingleton; use base 'Class::Singleton'; #------------------------------------------------------------------------ # define 'AnotherSingleton', a class derived from DerivedSingleton #------------------------------------------------------------------------ package AnotherSingleton; use base 'DerivedSingleton'; sub x { shift->{ x }; } #------------------------------------------------------------------------ # define 'ListSingleton', which uses a list reference as its type #------------------------------------------------------------------------ package ListSingleton; use base 'Class::Singleton'; sub _new_instance { my $class = shift; bless [], $class; } #------------------------------------------------------------------------ # define 'ConfigSingleton', which has specific configuration needs. #------------------------------------------------------------------------ package ConfigSingleton; use base 'Class::Singleton'; sub _new_instance { my $class = shift; my $config = shift || { }; my $self = { 'one' => 'This is the first parameter', 'two' => 'This is the second parameter', %$config, }; bless $self, $class; } #----------------------------------------------------------------------- # define 'DestructorSingleton' which has a destructor method #----------------------------------------------------------------------- package DestructorSingleton; use base 'Class::Singleton'; sub DESTROY { main::ok(1, 'destructor called' ); } #======================================================================== # -- TESTS -- #======================================================================== package main; # call Class::Singleton->instance() twice and expect to get the same # reference returned on both occasions. ok( ! Class::Singleton->has_instance(), 'no Class::Singleton instance yet' ); my $s1 = Class::Singleton->instance(); ok( $s1, 'created Class::Singleton instance 1' ); my $s2 = Class::Singleton->instance(); ok( $s2, 'created Class::Singleton instance 2' ); is( $s1, $s2, 'both instances are the same object' ); is( Class::Singleton->has_instance(), $s1, 'Class::Singleton has instance' ); # call MySingleton->instance() twice and expect to get the same # reference returned on both occasions. ok( ! DerivedSingleton->has_instance(), 'no DerivedSingleton instance yet' ); my $s3 = DerivedSingleton->instance(); ok( $s3, 'created DerivedSingleton instance 1' ); my $s4 = DerivedSingleton->instance(); ok( $s4, 'created DerivedSingleton instance 2' ); is( $s3, $s4, 'both derived instances are the same object' ); is( DerivedSingleton->has_instance(), $s3, 'DerivedSingleton has instance' ); # call MyOtherSingleton->instance() twice and expect to get the same # reference returned on both occasions. my $s5 = AnotherSingleton->instance( x => 10 ); ok( $s5, 'created AnotherSingleton instance 1' ); is( $s5->x, 10, 'first instance x is 10' ); my $s6 = AnotherSingleton->instance(); ok( $s6, 'created AnotherSingleton instance 2' ); is( $s6->x, 10, 'second instance x is 10' ); is( $s5, $s6, 'both another instances are the same object' ); #------------------------------------------------------------------------ # having checked that each instance of the same class is the same, we now # check that the instances of the separate classes are actually different # from each other #------------------------------------------------------------------------ isnt( $s1, $s3, "Class::Singleton and DerviedSingleton are different"); isnt( $s1, $s5, "Class::Singleton and AnotherSingleton are different"); isnt( $s3, $s5, "DerivedSingleton and AnotherSingleton are different"); #------------------------------------------------------------------------ # test ListSingleton #------------------------------------------------------------------------ my $ls1 = ListSingleton->instance(); ok( $ls1, 'created ListSingleton instance 1' ); my $ls2 = ListSingleton->instance(); ok( $ls2, 'created ListSingleton instance 2' ); is( $ls1, $ls2, 'both list instances are the same object' ); ok( $ls1 =~ /ARRAY/, "ListSingleton is a list reference"); #------------------------------------------------------------------------ # test ConfigSingleton #------------------------------------------------------------------------ # create a ConfigSingleton my $config = { 'foo' => 'This is foo' }; my $cs1 = ConfigSingleton->instance($config); ok( $cs1, 'created ConfigSingleton instance 1' ); # add another parameter to the config $config->{'bar'} = 'This is bar'; # shouldn't call new() so changes to $config shouldn't matter my $cs2 = ConfigSingleton->instance($config); ok( $cs2, 'created ConfigSingleton instance 2' ); is( $cs1, $cs2, 'both config instances are the same object' ); is( scalar(keys %$cs1), 3, "ConfigSingleton 1 has 3 keys"); is( scalar(keys %$cs2), 3, "ConfigSingleton 2 has 3 keys"); #----------------------------------------------------------------------- # test DestructorSingleton #----------------------------------------------------------------------- my $ds1 = DestructorSingleton->instance();