String-Glob-Permute-0.01/0000755004041600404160000000000011140672556015405 5ustar mschillimschilliString-Glob-Permute-0.01/t/0000755004041600404160000000000011140672556015650 5ustar mschillimschilliString-Glob-Permute-0.01/t/001Basic.t0000644004041600404160000000216611103702061017264 0ustar mschillimschilli# Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to # the contents of this file are licensed under the Perl Artistic License # (ver. 15 Aug 1997). ###################################################################### # Test suite for String::Glob::Permute # by Mike Schilli ###################################################################### use warnings; use strict; use Test::More; plan tests => 15; use String::Glob::Permute qw(string_glob_permute); my $pattern = "host{foo,bar}[2-4]"; my @hosts = string_glob_permute( $pattern ); is($hosts[0], "hostfoo2"); is($hosts[1], "hostbar2"); is($hosts[2], "hostfoo3"); is($hosts[3], "hostbar3"); is($hosts[4], "hostfoo4"); is($hosts[5], "hostbar4"); is(scalar @hosts, 6); $pattern = "host[1-3,5,10]"; @hosts = string_glob_permute( $pattern ); is($hosts[0], "host1"); is($hosts[4], "host10"); @hosts = string_glob_permute( "host[08-09,10]" ); is($hosts[0], "host08"); is($hosts[1], "host09"); is($hosts[2], "host10"); @hosts = string_glob_permute( "host[8-9,10]" ); is($hosts[0], "host8"); is($hosts[1], "host9"); is($hosts[2], "host10"); String-Glob-Permute-0.01/Makefile.PL0000644004041600404160000000112611103702061017337 0ustar mschillimschilli###################################################################### # Makefile.PL for String::Glob::Permute # 2008, Mike Schilli ###################################################################### use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'String::Glob::Permute', 'VERSION_FROM' => 'Permute.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Permute.pm', AUTHOR => 'Mike Schilli ') : ()), ); String-Glob-Permute-0.01/Changes0000644004041600404160000000025611103702061016663 0ustar mschillimschilli###################################################################### Revision history for Perl extension String::Glob::Permute 0.01 2008/10/31 * First CPAN release String-Glob-Permute-0.01/LICENSE.TXT0000644004041600404160000001451011140432701017053 0ustar mschillimschilli The Artistic License August 15, 1997 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 whomever 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. String-Glob-Permute-0.01/MANIFEST.SKIP0000644004041600404160000000011411103702061017257 0ustar mschillimschilliblib ^Makefile$ ^Makefile.old$ CVS .cvsignore docs MANIFEST.bak adm/release String-Glob-Permute-0.01/README0000644004041600404160000000645411140672554016274 0ustar mschillimschilli###################################################################### String::Glob::Permute 0.01 ###################################################################### NAME String::Glob::Permute - Expand {foo,bar,baz}[2-4] style string globs SYNOPSIS use String::Glob::Permute qw( string_glob_permute ); my $pattern = "host{foo,bar,baz}[2-4]"; for my $host (string_glob_permute( $pattern )) { print "$host\n"; } # hostfoo2 # hostbar2 # hostbaz2 # hostfoo3 # hostbar3 # hostbaz3 # hostfoo4 # hostbar4 # hostbaz4 DESCRIPTION The "string_glob_permute()" function provided by this module expands glob-like notations in text strings and returns all possible permutations. For example, to run a script on hosts host1, host2, and host3, you might write @hosts = string_glob_permute( "host[1-3]" ); and get a list of hosts back: ("host1", "host2", "host3"). Ranges with gaps are also supported, just separate the blocks by commas: @hosts = string_glob_permute( "host[1-3,5,9]" ); will return ("host1", "host2", "host3", "host5", "host9"). And, finally, using curly brackets and comma-separated lists of strings, as in @hosts = string_glob_permute( "host{dev,stag,prod}" ); you'll get permutations with each of the alternatives back: ("hostdev", "hoststag", "hostprod") back. All of the above can be combined, so my @hosts = string_glob_permute( "host{dev,stag}[3-4]" ); will result in the permutation ("hostdev3", "hoststag3", "hostdev4", "hoststag4"). The patterns allow numerical ranges only [1-3], no string ranges like [a-z]. Pattern must not contain blanks. The function returns a list of string permutations on success and "undef" in case of an error. A warning is also issued if the pattern cannot be recognized. Zero padding An expression like @hosts = string_glob_permute( "host[8-9,10]" ); # ("host8", "host9", "host10") will expand to ("host8", "host9", "host10"), featuring no zero-padding to create equal-length entries. If you want ("host08", "host09", "host10"), instead, pad all integers in the range expression accordingly: @hosts = string_glob_permute( "host[08-09,10]" ); # ("host08", "host09", "host10") Note on Perl's internal Glob Permutations Note that there's a little-known feature within Perl itself that does something similar, for example print "$_\n" for < foo{bar,baz} >; will print foobar foobaz if there is no file in the current directory that matches that pattern. String::Glob::Permute, on the other hand, expands irrespective of matching files, by simply always returning all possible permutations. It's also worth noting that Perl's internal Glob Permutation does not support String::Glob::Permute's [m,n] or [m-n] syntax. COPYRIGHT & LICENSE Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to the contents of this file are licensed under the Perl Artistic License (ver. 15 Aug 1997). AUTHOR Algorithm, Code: Rick Reed, Ryan Hamilton, Greg Olszewski. Module: 2008, Mike Schilli String-Glob-Permute-0.01/MANIFEST0000644004041600404160000000023411140672554016533 0ustar mschillimschilliChanges LICENSE.TXT Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml Module meta-data (added by MakeMaker) Permute.pm README t/001Basic.t String-Glob-Permute-0.01/Permute.pm0000644004041600404160000001151511140471036017355 0ustar mschillimschilli# Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to # the contents of this file are licensed under the Perl Artistic License # (ver. 15 Aug 1997). ########################################### package String::Glob::Permute; ########################################### use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(string_glob_permute); our $VERSION = "0.01"; ########################################### sub string_glob_permute { ########################################### my( $string_glob ) = @_; my @stringlist; my @patterns = ($string_glob); while (@patterns) { my $h = shift(@patterns); if ($h =~ /^(.*?)\[([^\]]+)\]([^,{[]*)(,(.*))?$/) { my($pre,$post) = ($1,$3); my @r = split(/,/,$2); for (@r) { if (/^(!?)(\d+)(-(\d+))?$/) { my $lo = $2; my $hi = $3 ? $4 : $lo; my $fmt = "%d"; # Expand [09-11] to ("09", "10", "11") instead of # ("9", "10", "11"). if (length($lo) == length($hi) && length($lo) > 1) { $fmt = "%0" . length($lo) . "d"; } for (my $n = $lo; $n <= $hi; $n++) { my $hn = $pre . sprintf($fmt, $n) . $post; if ($1) { @stringlist = grep { $_ ne $hn } @stringlist; @patterns = grep { $_ ne $hn } @patterns; } else { push(@patterns,$hn); } } } else { warn("Unrecognized host pattern: $h"); return undef; } } if ($4) { push(@patterns,$5); } } elsif ($h =~ /^(.*?)\{([^\}]+)\}([^,[{]*)(,(.*))?$/) { my($pre,$post) = ($1,$3); my @r = split(/,/,$2); for (@r) { push(@patterns,$pre.$_.$post); } if ($4) { push(@patterns,$5); } } else { my @h = split(/,/,$h); push(@stringlist,@h); } } return @stringlist; } 1; __END__ =head1 NAME String::Glob::Permute - Expand {foo,bar,baz}[2-4] style string globs =head1 SYNOPSIS use String::Glob::Permute qw( string_glob_permute ); my $pattern = "host{foo,bar,baz}[2-4]"; for my $host (string_glob_permute( $pattern )) { print "$host\n"; } # hostfoo2 # hostbar2 # hostbaz2 # hostfoo3 # hostbar3 # hostbaz3 # hostfoo4 # hostbar4 # hostbaz4 =head1 DESCRIPTION The C function provided by this module expands glob-like notations in text strings and returns all possible permutations. For example, to run a script on hosts host1, host2, and host3, you might write @hosts = string_glob_permute( "host[1-3]" ); and get a list of hosts back: ("host1", "host2", "host3"). Ranges with gaps are also supported, just separate the blocks by commas: @hosts = string_glob_permute( "host[1-3,5,9]" ); will return ("host1", "host2", "host3", "host5", "host9"). And, finally, using curly brackets and comma-separated lists of strings, as in @hosts = string_glob_permute( "host{dev,stag,prod}" ); you'll get permutations with each of the alternatives back: ("hostdev", "hoststag", "hostprod") back. All of the above can be combined, so my @hosts = string_glob_permute( "host{dev,stag}[3-4]" ); will result in the permutation ("hostdev3", "hoststag3", "hostdev4", "hoststag4"). The patterns allow numerical ranges only [1-3], no string ranges like [a-z]. Pattern must not contain blanks. The function returns a list of string permutations on success and C in case of an error. A warning is also issued if the pattern cannot be recognized. =head2 Zero padding An expression like @hosts = string_glob_permute( "host[8-9,10]" ); # ("host8", "host9", "host10") will expand to ("host8", "host9", "host10"), featuring no zero-padding to create equal-length entries. If you want ("host08", "host09", "host10"), instead, pad all integers in the range expression accordingly: @hosts = string_glob_permute( "host[08-09,10]" ); # ("host08", "host09", "host10") =head2 Note on Perl's internal Glob Permutations Note that there's a little-known feature within Perl itself that does something similar, for example print "$_\n" for < foo{bar,baz} >; will print foobar foobaz if there is no file in the current directory that matches that pattern. String::Glob::Permute, on the other hand, expands irrespective of matching files, by simply always returning all possible permutations. It's also worth noting that Perl's internal Glob Permutation does not support String::Glob::Permute's [m,n] or [m-n] syntax. =head1 COPYRIGHT & LICENSE Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to the contents of this file are licensed under the Perl Artistic License (ver. 15 Aug 1997). =head1 AUTHOR Algorithm, Code: Rick Reed, Ryan Hamilton, Greg Olszewski. Module: 2008, Mike Schilli String-Glob-Permute-0.01/META.yml0000644004041600404160000000046211140672556016660 0ustar mschillimschilli# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: String-Glob-Permute version: 0.01 version_from: Permute.pm installdirs: site requires: distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17