String-Dirify-1.02000755001750001750 011511722552 12706 5ustar00ronron000000000000String-Dirify-1.02/Build.PL000444001750001750 52111511722552 14315 0ustar00ronron000000000000use Module::Build; Module::Build -> new ( module_name => 'String::Dirify', license => 'artistic', dist_abstract => 'Convert a string into a directory name', dist_author => 'Ron Savage ', build_requires => { Test::More => 0, Test::Pod => 0, }, requires => { }, ) -> create_build_script(); String-Dirify-1.02/CHANGES000444001750001750 52711511722552 14022 0ustar00ronron000000000000Revision history for Perl extension String::Dirify. 1.02 Fri Jan 7 10:41:00 2011 - Add explicit copyright text in Source/Dirify.pm for Debian packaging. - Add newline at end of t/pod.t. 1.01 Wed Feb 10 13:53:05 2010 - Add META.yml. Update MANIFEST.SKIP. Add MANIFEST and MYMETA.yml. 1.00 Fri Jun 26 11:09:00 2009 - Original version String-Dirify-1.02/META.yml000444001750001750 101511511722552 14311 0ustar00ronron000000000000--- abstract: 'Convert a string into a directory name' author: - 'Ron Savage ' build_requires: Test::More: 0 Test::Pod: 0 configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3607' license: artistic meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: String-Dirify provides: String::Dirify: file: lib/String/Dirify.pm version: 1.02 resources: license: http://www.perlfoundation.org/artistic_license_1_0 version: 1.02 String-Dirify-1.02/README000444001750001750 454611511722552 13734 0ustar00ronron000000000000NAME "String::Dirify" - Convert a string into a directory name Synopsis use String::Dirify; my($dir_1) = String::Dirify -> dirify('frobnitz'); Or: use String::Dirify ':all'; my($dir_2) = dirify('bar baz'); Or even: use String::Dirify; my($sd) = String::Dirify -> new(); my($dir_3) = $sd -> dirify('!Q@W#E$R%T^Y'); Description "String::Dirify" is a pure Perl module. This module allows you to convert a string (possibly containing high ASCII characters, and even HTML) into another, lower-cased, string which can be used as a directory name. For usage, see the Synopsis. This code is derived from similar code in Movable Type. Method: dirify($string [, $separator]) Returns a string, which can be used as a directory name. The default separator is '_'. Each run of spaces in the string is replaced by this separator. Algorithm 1: Each high ASCII character is replaced by its normal equivalent 2: The string is converted to lower case 3: Any HTML (including HTML entities) in the string is removed 4: Any characters which are not (Perl) words, spaces or hyphens, are removed 5: Runs of spaces are converted to the separator character For more details about this character, see the discussion of the dirify() method (above). Melody 'v' Movable Type See http://openmelody.org for details. Backwards Compatibility with Movable Type Unfortunately, Movable Type's usage of dirify() allows a fake separator - '1' - to be used for the second parameter in the call to dirify(). The '1' triggered usage of '_' as the separator, rather than the '1' provided. This 'feature' has been preserved in "String::Dirify", but is discouraged. Instead, simply drop the second parameter and let the code default to '_'. Distributions This module is available as a Unix-style distro (*.tgz). See http://savage.net.au/Perl-modules.html for details. Authors "String::Dirify" started out as part of Movable Type's code. Then, Mark Stosberg cut down the original code to provide just the English/ISO/ASCII features. Lastly, the code was cleaned up, tests added, and all packaged, by Ron Savage ** in 2009. Home page: http://savage.net.au/index.html String-Dirify-1.02/MANIFEST000444001750001750 23311511722552 14152 0ustar00ronron000000000000Build.PL Changelog.ini CHANGES lib/String/Dirify.pm Makefile.PL MANIFEST This list of files META.yml README t/general.t t/import.t t/pod.t t/separator.t String-Dirify-1.02/Makefile.PL000444001750001750 113211511722552 15012 0ustar00ronron000000000000use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile ( ($] ge '5.005') ? ( AUTHOR => 'Ron Savage (ron@savage.net.au)', ABSTRACT => 'Convert a string into a directory name', ) : (), clean => { FILES => 'blib/* Makefile MANIFEST String-Dirify-*' }, dist => { COMPRESS => 'gzip', SUFFIX => 'gz' }, DISTNAME => 'String-Dirify', NAME => 'String::Dirify', PL_FILES => {}, PREREQ_PM => { Test::More => 0, Test::Pod => 0, }, VERSION_FROM => 'lib/String/Dirify.pm', ); String-Dirify-1.02/Changelog.ini000444001750001750 70711511722552 15417 0ustar00ronron000000000000[Module] Name=String::Dirify Changelog.Creator=Module::Metadata::Changes V 1.08 Changelog.Parser=Config::IniFiles V 2.65 [V 1.02] Date=2011-01-07T10:41:00 Comments= < 3; use String::Dirify 'dirify'; ok(dirify(" \xc0\xe0\xdf\xff\xd4", 1) eq '_aassyo', 'Test 1: High ASCII chars'); ok(dirify(' !Q@W#E$R%T^Y', '_') eq '_qwerty', 'Test 2: Punctuation'); ok(dirify(' html&ok', 'x') eq 'xhtmlok', 'Test 3: HTML'); String-Dirify-1.02/t/general.t000555001750001750 76611511722552 15104 0ustar00ronron000000000000use Test::More tests => 6; BEGIN{ use_ok('String::Dirify'); } my($sd) = String::Dirify -> new(); ok($sd -> dirify("\xc0\xe0\xdf\xff\xd4") eq 'aassyo', 'Test 2: High ASCII chars'); ok($sd -> dirify('!Q@W#E$R%T^Y') eq 'qwerty', 'Test 3: Punctuation'); ok($sd -> dirify('html&ok') eq 'htmlok', 'Test 4: HTML'); ok($sd -> dirify('') eq 'cdatax', 'Test 5: CDATA'); ok(String::Dirify -> dirify('not.obj') eq 'notobj', 'Test 6: Object-free'); String-Dirify-1.02/t/pod.t000555001750001750 20411511722552 14234 0ustar00ronron000000000000use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); String-Dirify-1.02/t/import.t000555001750001750 53311511722552 14771 0ustar00ronron000000000000use Test::More tests => 4; use String::Dirify ':all'; ok(dirify("\xc0\xe0\xdf\xff\xd4") eq 'aassyo', 'Test 1: High ASCII chars'); ok(dirify('!Q@W#E$R%T^Y') eq 'qwerty', 'Test 2: Punctuation'); ok(dirify('html&ok') eq 'htmlok', 'Test 3: HTML'); ok(dirify('') eq 'cdatax', 'Test 4: CDATA'); String-Dirify-1.02/lib000755001750001750 011511722552 13454 5ustar00ronron000000000000String-Dirify-1.02/lib/String000755001750001750 011511722552 14722 5ustar00ronron000000000000String-Dirify-1.02/lib/String/Dirify.pm000444001750001750 1524111511722552 16666 0ustar00ronron000000000000package String::Dirify; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows the declaration use String::Dirify ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( dirify ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '1.02'; # ------------------------------------------------ my(%high_ASCII_char) = ( "\xc0" => 'A', # A` "\xe0" => 'a', # a` "\xc1" => 'A', # A' "\xe1" => 'a', # a' "\xc2" => 'A', # A^ "\xe2" => 'a', # a^ "\xc4" => 'A', # A: "\xe4" => 'a', # a: "\xc5" => 'A', # Aring "\xe5" => 'a', # aring "\xc6" => 'AE', # AE "\xe6" => 'ae', # ae "\xc3" => 'A', # A~ "\xe3" => 'a', # a~ "\xc8" => 'E', # E` "\xe8" => 'e', # e` "\xc9" => 'E', # E' "\xe9" => 'e', # e' "\xca" => 'E', # E^ "\xea" => 'e', # e^ "\xcb" => 'E', # E: "\xeb" => 'e', # e: "\xcc" => 'I', # I` "\xec" => 'i', # i` "\xcd" => 'I', # I' "\xed" => 'i', # i' "\xce" => 'I', # I^ "\xee" => 'i', # i^ "\xcf" => 'I', # I: "\xef" => 'i', # i: "\xd2" => 'O', # O` "\xf2" => 'o', # o` "\xd3" => 'O', # O' "\xf3" => 'o', # o' "\xd4" => 'O', # O^ "\xf4" => 'o', # o^ "\xd6" => 'O', # O: "\xf6" => 'o', # o: "\xd5" => 'O', # O~ "\xf5" => 'o', # o~ "\xd8" => 'O', # O/ "\xf8" => 'o', # o/ "\xd9" => 'U', # U` "\xf9" => 'u', # u` "\xda" => 'U', # U' "\xfa" => 'u', # u' "\xdb" => 'U', # U^ "\xfb" => 'u', # u^ "\xdc" => 'U', # U: "\xfc" => 'u', # u: "\xc7" => 'C', # ,C "\xe7" => 'c', # ,c "\xd1" => 'N', # N~ "\xf1" => 'n', # n~ "\xdd" => 'Y', # Yacute "\xfd" => 'y', # yacute "\xdf" => 'ss', # szlig "\xff" => 'y' # yuml ); my($high_ASCII_re) = join '|', keys %high_ASCII_char; # ------------------------------------------------ sub convert_high_ascii { # require MT::I18N; # MT::I18N::convert_high_ascii(@_); my($self, $s) = @_; $s =~ s/($high_ASCII_re)/$high_ASCII_char{$1}/g; return $s; } # End of convert_high_ascii. # ------------------------------------------------ # Re-use just the parts we need of Movable Type's 'dirify' function. # The purpose is to take any string and make it a valid directory name. sub dirify { # ($MT::VERSION && MT->instance->{cfg}->PublishCharset =~ m/utf-?8/i) # ? utf8_dirify(@_) : iso_dirify(@_); my($self); if (ref $_[0]) # Handle calls like $o = String::Dirify -> new(); $d = $o -> dirify($s). { $self = shift; } elsif ($_[0] eq __PACKAGE__) # Handle calls like $d = String::Dirify -> dirify($s). { $self = new(shift @_); } else # Handle calls like $d = dirify($s). { $self = new(__PACKAGE__); } return $self -> iso_dirify(@_); } # End of dirify. # ------------------------------------------------ sub iso_dirify { my($self, $s, $sep) = @_; return '' if (! defined $s); $sep = defined($sep) && ($sep ne '1') ? $sep : '_'; $s = $self -> convert_high_ascii($s); # Convert high-ASCII chars to 7-bit. $s = $self -> remove_html(lc $s); # Lower case, and remove HTML tags. $s =~ s!&[^;\s]+;!!gs; # Remove HTML entities. $s =~ s![^\w\s-]!!gs; # Remove non-word/space chars. $s =~ s!\s+!$sep!gs; # Change runs of spaces to the separator char. return $s; } # End of iso_dirify. # ------------------------------------------------ sub new { my($class) = @_; return bless {}, $class; } # End of new. # ------------------------------------------------ sub remove_html { my($self, $text) = @_; return $text if (! defined $text); # Suppress warnings. return $text if $text =~ m/^<\!\[CDATA\[/i; # We need /i because lc() has been called. $text =~ s!<[^>]+>!!gs; # Remove all '<'s which have matching '>'s. $text =~ s! - Convert a string into a directory name =head1 Synopsis use String::Dirify; my($dir_1) = String::Dirify -> dirify('frobnitz'); Or: use String::Dirify ':all'; my($dir_2) = dirify('bar baz'); Or even: use String::Dirify; my($sd) = String::Dirify -> new(); my($dir_3) = $sd -> dirify('!Q@W#E$R%T^Y'); =head1 Description C is a pure Perl module. This module allows you to convert a string (possibly containing high ASCII characters, and even HTML) into another, lower-cased, string which can be used as a directory name. For usage, see the Synopsis. This code is derived from similar code in Movable Type. =head1 Method: dirify($string [, $separator]) Returns a string, which can be used as a directory name. The default separator is '_'. Each run of spaces in the string is replaced by this separator. =head1 Algorithm =over 4 =item 1: Each high ASCII character is replaced by its normal equivalent =item 2: The string is converted to lower case =item 3: Any HTML (including HTML entities) in the string is removed =item 4: Any characters which are not (Perl) words, spaces or hyphens, are removed =item 5: Runs of spaces are converted to the separator character For more details about this character, see the discussion of the dirify() method (above). =back =head1 Melody 'v' Movable Type See http://openmelody.org for details. =head1 Backwards Compatibility with Movable Type Unfortunately, Movable Type's usage of dirify() allows a fake separator - '1' - to be used for the second parameter in the call to dirify(). The '1' triggered usage of '_' as the separator, rather than the '1' provided. This 'feature' has been preserved in C, but is discouraged. Instead, simply drop the second parameter and let the code default to '_'. =head1 Distributions This module is available as a Unix-style distro (*.tgz). See http://savage.net.au/Perl-modules.html for details. =head1 Authors C started out as part of Movable Type's code. Then, Mark Stosberg cut down the original code to provide just the English/ISO/ASCII features. Lastly, the code was cleaned up, tests added, and all packaged, by Ron Savage Iron@savage.net.auE> in 2009. Home page: http://savage.net.au/index.html Copyright (c) 2009, Mark Stosberg, Ron Savage. Copyright (c) 2010, 2011, Ron Savage. =cut