Dispatch-Class-0.04/0000755000175000017500000000000015020065221013216 5ustar maukemaukeDispatch-Class-0.04/Makefile_PL_settings.plx0000644000175000017500000000126215017772347020020 0ustar maukemauke# vi:set ft=perl: use strict; use warnings; return { NAME => 'Dispatch::Class', AUTHOR => q{Lukas Mai }, LICENSE => 'perl', MIN_PERL_VERSION => '5.6.0', CONFIGURE_REQUIRES => {}, BUILD_REQUIRES => {}, TEST_REQUIRES => { 'Test::More' => 0, 'IO::Handle' => 0, }, PREREQ_PM => { 'parent' => 0, 'warnings' => 0, 'strict' => 0, 'Exporter::Tiny' => 0, 'Scalar::Util' => 1, }, depend => { Makefile => '$(VERSION_FROM)', }, REPOSITORY => [ codeberg => 'mauke' ], BUGTRACKER => 'https://codeberg.org/mauke/Dispatch-Class/issues', }; Dispatch-Class-0.04/Makefile.PL0000644000175000017500000001426215017634606015214 0ustar maukemaukeuse strict; use warnings; use ExtUtils::MakeMaker; use File::Spec (); use File::Find (); sub MY::postamble { my ($self, %args) = @_; if ((my $harness_options = delete $args{HARNESS_OPTIONS}) && $self->can('is_make_type')) { my $value = join ':', @$harness_options; if ($self->is_make_type('gmake')) { $args{text} .= "export HARNESS_OPTIONS := $value\n"; } elsif ($self->is_make_type('nmake')) { $args{text} .= "!if [set HARNESS_OPTIONS=$value]\n!endif\n"; } } $args{text} || '' } sub find_tests_recursively_in { my ($dir) = @_; -d $dir or die "$dir is not a directory"; my %seen; my $wanted = sub { /\.t\z/ or return; my $directories = (File::Spec->splitpath($File::Find::name))[1]; my $depth = grep $_ ne '', File::Spec->splitdir($directories); $seen{$depth} = 1; }; File::Find::find($wanted, $dir); join ' ', map { $dir . '/*' x $_ . '.t' } sort { $a <=> $b } keys %seen } $::MAINT_MODE = !-f 'META.yml'; my $settings_file = 'Makefile_PL_settings.plx'; my %settings = %{do "./$settings_file" or die "Internal error: can't do $settings_file: ", $@ || $!}; (do './maint/eumm-fixup.pl' || die $@ || $!)->(\%settings) if $::MAINT_MODE; { $settings{depend}{Makefile} .= " $settings_file"; $settings{LICENSE} ||= 'perl'; $settings{PL_FILES} ||= {}; $settings{CONFIGURE_REQUIRES}{strict} ||= 0; $settings{CONFIGURE_REQUIRES}{warnings} ||= 0; $settings{CONFIGURE_REQUIRES}{'File::Find'} ||= 0; $settings{CONFIGURE_REQUIRES}{'File::Spec'} ||= 0; for ($settings{CONFIGURE_REQUIRES}{'ExtUtils::MakeMaker'}) { $_ = '6.48' if !$_ || $_ < 6.48; } my $module_file = $settings{NAME}; $module_file =~ s!::!/!g; $module_file = "lib/$module_file.pm"; $settings{VERSION_FROM} ||= $module_file; $settings{ABSTRACT_FROM} ||= $module_file; $settings{test}{TESTS} ||= do { my $extra_test_dirs = delete $settings{EXTRA_TEST_DIRS}; join ' ', map find_tests_recursively_in($_), 't', @{$extra_test_dirs || []} }; $settings{DISTNAME} ||= do { my $name = $settings{NAME}; $name =~ s!::!-!g; $name }; $settings{clean}{FILES} ||= "$settings{DISTNAME}-*"; $settings{dist}{COMPRESS} ||= 'gzip -9f'; $settings{dist}{SUFFIX} ||= '.gz'; my $version = $settings{VERSION} || MM->parse_version($settings{VERSION_FROM}); if ($version =~ s/-TRIAL[0-9]*\z//) { $settings{META_MERGE}{release_status} ||= 'unstable'; $settings{META_MERGE}{version} ||= $version; $settings{XS_VERSION} ||= $version; } $settings{META_MERGE}{'meta-spec'}{version} ||= 2; $settings{META_MERGE}{dynamic_config} ||= 0; push @{$settings{META_MERGE}{no_index}{directory}}, 'xt'; if (my $dev = delete $settings{DEVELOP_REQUIRES}) { @{$settings{META_MERGE}{prereqs}{develop}{requires}}{keys %$dev} = values %$dev; } if (my $rec = delete $settings{RECOMMENDS}) { @{$settings{META_MERGE}{prereqs}{runtime}{recommends}}{keys %$rec} = values %$rec; } if (my $sug = delete $settings{SUGGESTS}) { @{$settings{META_MERGE}{prereqs}{runtime}{suggests}}{keys %$sug} = values %$sug; } if (my $repo = delete $settings{REPOSITORY}) { if (ref($repo) eq 'ARRAY') { my ($type, @args) = @$repo; my %sites = ( github => 'github.com', codeberg => 'codeberg.org', ); if (defined(my $site = $sites{$type})) { my ($account, $project) = @args; $project ||= '%d'; $project =~ s{%(L?)(.)}{ my $x = $2 eq '%' ? '%' : $2 eq 'd' ? $settings{DISTNAME} : $2 eq 'm' ? $settings{NAME} : die "Internal error: unknown placeholder %$1$2"; $1 ? lc($x) : $x }seg; my $addr = "$site/$account/$project"; $repo = { type => 'git', url => "https://$addr.git", web => "https://$addr", }; } else { die "Internal error: unknown REPOSITORY type '$type'"; } } ref($repo) eq 'HASH' or die "Internal error: REPOSITORY must be a hashref, not $repo"; @{$settings{META_MERGE}{resources}{repository}}{keys %$repo} = values %$repo; } if (my $bugtracker = delete $settings{BUGTRACKER}) { $settings{META_MERGE}{resources}{bugtracker}{web} = $bugtracker; } if (my $harness_options = delete $settings{HARNESS_OPTIONS}) { $settings{postamble}{HARNESS_OPTIONS} = $harness_options; } } (my $mm_version = ExtUtils::MakeMaker->VERSION) =~ tr/_//d; if ($mm_version < 6.63_03) { $settings{META_MERGE}{resources}{repository} = $settings{META_MERGE}{resources}{repository}{url} if $settings{META_MERGE}{resources} && $settings{META_MERGE}{resources}{repository} && $settings{META_MERGE}{resources}{repository}{url}; delete $settings{META_MERGE}{'meta-spec'}{version}; } elsif ($mm_version < 6.67_04) { # Why? For the glory of satan, of course! no warnings qw(redefine); *ExtUtils::MM_Any::_add_requirements_to_meta_v1_4 = \&ExtUtils::MM_Any::_add_requirements_to_meta_v2; } { my $merge_key_into = sub { my ($target, $source) = @_; %{$settings{$target}} = (%{$settings{$target}}, %{delete $settings{$source}}); }; $merge_key_into->('BUILD_REQUIRES', 'TEST_REQUIRES') if $mm_version < 6.63_03; $merge_key_into->('CONFIGURE_REQUIRES', 'BUILD_REQUIRES') if $mm_version < 6.55_01; $merge_key_into->('PREREQ_PM', 'CONFIGURE_REQUIRES') if $mm_version < 6.51_03; } delete $settings{MIN_PERL_VERSION} if $mm_version < 6.47_01; delete $settings{META_MERGE} if $mm_version < 6.46; delete $settings{LICENSE} if $mm_version < 6.30_01; delete $settings{ABSTRACT_FROM} if $mm_version < 6.06_03; delete $settings{AUTHOR} if $mm_version < 6.06_03; WriteMakefile %settings; Dispatch-Class-0.04/META.json0000664000175000017500000000340315020065221014641 0ustar maukemauke{ "abstract" : "dispatch on the type (class) of an argument", "author" : [ "Lukas Mai " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Dispatch-Class", "no_index" : { "directory" : [ "t", "inc", "xt" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.48", "File::Find" : "0", "File::Spec" : "0", "strict" : "0", "warnings" : "0" } }, "develop" : { "requires" : { "Pod::Markdown::Githubert" : "0", "Pod::Text" : "4.09", "Test::Pod" : "1.22" } }, "runtime" : { "requires" : { "Exporter::Tiny" : "0", "Scalar::Util" : "1", "parent" : "0", "perl" : "5.006000", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "IO::Handle" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://codeberg.org/mauke/Dispatch-Class/issues" }, "repository" : { "type" : "git", "url" : "https://codeberg.org/mauke/Dispatch-Class.git", "web" : "https://codeberg.org/mauke/Dispatch-Class" } }, "version" : "0.04", "x_serialization_backend" : "JSON::PP version 4.16" } Dispatch-Class-0.04/t/0000755000175000017500000000000015020065221013461 5ustar maukemaukeDispatch-Class-0.04/t/basic.t0000644000175000017500000000317415017623503014745 0ustar maukemauke#!perl use warnings FATAL => 'all'; use strict; use Test::More tests => 17; use Dispatch::Class qw(class_case dispatch); use IO::Handle (); { package DummyClass; sub new { bless {}, $_[0] } sub subclass { my $class = shift; for my $subclass (@_) { no strict 'refs'; push @{$subclass . '::ISA'}, $class; } } } DummyClass->subclass(qw(Some::Class Other::Class)); my $analyze = class_case( 'Some::Class' => 1, 'Other::Class' => 2, 'UNIVERSAL' => "???", ); is $analyze->(Other::Class->new), 2; is $analyze->(IO::Handle->new), "???"; is $analyze->(["not an object"]), undef; is +() = $analyze->(["not an object"]), 0; DummyClass->subclass(qw(Mammal Tree)); Mammal->subclass(qw(Dog Bunny)); Dog->subclass(qw(Dog::Tiny Barky Setter)); Tree->subclass(qw(Barky)); my @trace; my $dispatch = dispatch( map { my $class = $_; $_ => sub { push @trace, $class; return $class, $_[0]; } } qw( Tree Dog::Tiny Dog ARRAY Mammal :str HASH * ) ); my @prep = ( 'Tree' => Tree->new, 'Mammal' => Mammal->new, 'Dog' => Dog->new, 'Mammal' => Bunny->new, 'Dog::Tiny' => Dog::Tiny->new, 'Tree' => Barky->new, 'Dog' => Setter->new, 'ARRAY' => [1, 2, 3], 'HASH' => {A => 'b'}, ':str' => "foo bar", ':str' => 5, '*' => IO::Handle->new, ); my @ks; for (my $i = 0; $i < @prep; $i += 2) { my ($k, $v) = @prep[$i, $i + 1]; my @got = $dispatch->($v); is_deeply \@got, [$k, $v]; push @ks, $k; } is_deeply \@trace, \@ks; Dispatch-Class-0.04/t/00-load.t0000644000175000017500000000023315017623503015011 0ustar maukemauke#!perl use Test::More tests => 1; BEGIN { use_ok( 'Dispatch::Class' ); } diag( "Testing Dispatch::Class $Dispatch::Class::VERSION, Perl $], $^X" ); Dispatch-Class-0.04/Changes0000644000175000017500000000110615020065141014510 0ustar maukemaukeRevision history for Dispatch-Class 0.04 2025-06-04 - fix declared prerequisites: parent was missing entirely; Scalar::Util now officially needs version 1.0+ - no other changes 0.03 2025-06-03 - cosmetic updates to documentation - switch bug tracker to codeberg - add a LICENSE file as requested by Red Hat: https://bugzilla.redhat.com/show_bug.cgi?id=2342791 0.02 2014-11-29 - Use Exporter::Tiny instead of Sub::Exporter. 0.01 2014-01-04 First version, released on an unsuspecting world. Dispatch-Class-0.04/LICENSE0000644000175000017500000004552115017642662014252 0ustar maukemaukeCopyright 2013, 2014 Lukas Mai. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. (Full copies of these two licenses are included below.) --[ GNU General Public License ]---------------------------------------- GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 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 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, see . 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 Moe Ghoul, President of Vice That's all there is to it! --[ Artistic License ]-------------------------------------------------- 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 Dispatch-Class-0.04/MANIFEST.SKIP0000644000175000017500000000004115017635353015126 0ustar maukemauke#!include_default ^docs/ ^maint/ Dispatch-Class-0.04/META.yml0000664000175000017500000000155115020065221014473 0ustar maukemauke--- abstract: 'dispatch on the type (class) of an argument' author: - 'Lukas Mai ' build_requires: IO::Handle: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '6.48' File::Find: '0' File::Spec: '0' strict: '0' warnings: '0' dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 7.70, 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: Dispatch-Class no_index: directory: - t - inc - xt requires: Exporter::Tiny: '0' Scalar::Util: '1' parent: '0' perl: '5.006000' strict: '0' warnings: '0' resources: bugtracker: https://codeberg.org/mauke/Dispatch-Class/issues repository: https://codeberg.org/mauke/Dispatch-Class.git version: '0.04' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Dispatch-Class-0.04/Makefile_PL_settings_maint.plx0000644000175000017500000000034115017633363021177 0ustar maukemaukeuse strict; use warnings; sub { my ($opt) = @_; $opt->{DEVELOP_REQUIRES} = { 'Test::Pod' => 1.22, 'Pod::Markdown::Githubert' => 0, 'Pod::Text' => 4.09, }; } Dispatch-Class-0.04/xt/0000755000175000017500000000000015020065221013651 5ustar maukemaukeDispatch-Class-0.04/xt/pod.t0000644000175000017500000000011215017635156014632 0ustar maukemauke#!perl use strict; use warnings; use Test::Pod 1.22; all_pod_files_ok(); Dispatch-Class-0.04/MANIFEST0000644000175000017500000000066315020065222014355 0ustar maukemaukeChanges lib/Dispatch/Class.pm LICENSE Makefile.PL Makefile_PL_settings.plx Makefile_PL_settings_maint.plx MANIFEST MANIFEST.SKIP t/00-load.t t/basic.t xt/pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) README generated from Dispatch::Class POD (added by maint/eumm-fixup.pl) Dispatch-Class-0.04/README0000664000175000017500000000140315020065221014076 0ustar maukemaukeNAME Dispatch::Class - dispatch on the type (class) of an argument INSTALLATION To download and install this module, use your favorite CPAN client, e.g. "cpan": cpan Dispatch::Class Or "cpanm": cpanm Dispatch::Class To do it manually, run the following commands (after downloading and unpacking the tarball): perl Makefile.PL make make test make install COPYRIGHT & LICENSE Copyright 2013, 2014 Lukas Mai. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See for more information. Dispatch-Class-0.04/lib/0000755000175000017500000000000015020065221013764 5ustar maukemaukeDispatch-Class-0.04/lib/Dispatch/0000755000175000017500000000000015020065221015523 5ustar maukemaukeDispatch-Class-0.04/lib/Dispatch/Class.pm0000644000175000017500000001227215020064674017145 0ustar maukemaukepackage Dispatch::Class; use warnings; use strict; our $VERSION = '0.04'; use Scalar::Util qw(blessed); use parent 'Exporter::Tiny'; our @EXPORT_OK = qw( class_case dispatch ); sub class_case { my @prototable = @_; sub { my ($x) = @_; my $blessed = blessed $x; my $ref = ref $x; my $DOES; my @table = @prototable; while (my ($key, $value) = splice @table, 0, 2) { return $value if !defined $key ? !defined $x : $key eq '*' ? 1 : $key eq ':str' ? !$ref : $key eq $ref ? 1 : $blessed && ($DOES ||= $x->can('DOES') || 'isa', $x->$DOES($key)) ; } () } } sub dispatch { my $chk = &class_case; sub { ($chk->($_[0]) || return)->($_[0]) } } 'ok' __END__ =head1 NAME Dispatch::Class - dispatch on the type (class) of an argument =head1 SYNOPSIS =for highlighter language=perl use Dispatch::Class qw( class_case dispatch ); # analyze the class of an object my $analyze = class_case( 'Some::Class' => 1, 'Other::Class' => 2, 'UNIVERSAL' => "???", ); my $foo = $analyze->(Other::Class->new); # 2 my $bar = $analyze->(IO::Handle->new); # "???" my $baz = $analyze->(["not an object"]); # undef # build a dispatcher my $dispatch = dispatch( 'Dog::Tiny' => sub { ... }, # handle objects of the class Dog::Tiny 'Dog' => sub { ... }, 'Mammal' => sub { ... }, 'Tree' => sub { ... }, 'ARRAY' => sub { ... }, # handle array refs ':str' => sub { ... }, # handle non-reference strings '*' => sub { ... }, # handle any value ); # call the appropriate handler, passing $obj as an argument my $result = $dispatch->($obj); =head1 DESCRIPTION This module offers a (mostly) simple way to check the class of an object and handle specific cases specially. =head2 Functions The following functions are available and can be imported on request: =over =item C C takes a list of C pairs and returns a code reference that (when called on an object) will analyze the object's class according to the rules described below and return the corresponding I of the first matching I. Example: my $subref = class_case( KEY1 => VALUE1, KEY2 => VALUE2, ... ); my $value = $subref->($some_object); This will check the class of C<$some_object> against C, C, ... in order and return the corresponding C of the first match. If no key matches, an empty list/undef is returned in list/scalar context, respectively. The following things can be used as keys: =over =item C<*> This will match any value. No actual check is performed. =item C<:str> This special key will match any non-reference. =item C, C, C, ... These values match references of the specified type even if they aren't objects (i.e. not Led|perlfunc/bless>). That is, for unblessed references the string returned by L|perlfunc/ref> is compared with L|perlop/"Equality Operators">. =item CLASS Any other string is interpreted as a class name and matches if the input value is an object for which C<< $obj->isa($CLASS) >> is true. To match any kind of object (blessed value), use the key C<'UNIVERSAL'>. Starting with L Perl supports checking for roles with L|UNIVERSAL/obj-DOES-ROLE->, so C actually uses C<< $obj->DOES($CLASS) >> instead of C. This still returns true for normal base classes but it also accepts roles that have been composed into the object's class. =back =item C This works like C above, but the Is must be code references and get invoked automatically: sub dispatch { my $analyze = class_case @_; sub { my ($obj) = @_; my $handler = $analyze->($obj) or return; $handler->($obj) } } That is, the matching object is passed on to the matched Is and the return value of the inner sub is whatever the handler returns (or the empty list/undef if no I matches). =back This module uses L|Exporter::Tiny>, so you can rename the imported functions at L|perlfunc/use> time. =head1 SEE ALSO L =head1 AUTHOR Lukas Mai, C<< >> =begin :README =head1 INSTALLATION To download and install this module, use your favorite CPAN client, e.g. L|cpan>: =for highlighter language=sh cpan Dispatch::Class Or L|cpanm>: cpanm Dispatch::Class To do it manually, run the following commands (after downloading and unpacking the tarball): perl Makefile.PL make make test make install =end :README =head1 COPYRIGHT & LICENSE Copyright 2013, 2014 Lukas Mai. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See L for more information. =cut