-
-
20 Aug 2019 16:10:30 UTC
- Distribution: Text-CleanFragment
- Module version: 0.04
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (0)
- Testers (3562 / 1 / 0)
- Kwalitee
Bus factor: 1- 100.00% Coverage
- License: perl_5
- Perl: v5.8.0
- Activity
24 month- Tools
- Download (9.93KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:1 non-PAUSE userNAME
Text::CleanFragment - clean up text to use as URL fragment or filename
SYNOPSIS
my $title = "Do p\x{00FC}t <this> into/URL's?"; my $id = 42; my $url = join "/", $id, clean_fragment( $title ); # 42/Do_put_this_into_URLs
DESCRIPTION
This module downgrades strings of text to match
/^[-._A-Za-z0-9]*$/
or, to be more exact
/^([A-Za-z0-9]([-._A-Za-z0-9]*[A-Za-z0-9])?$/
This makes the return values safe to be used as URL fragments or as file names on many file systems where whitespace and characters outside of the Latin alphabet are undesired or problematic.
FUNCTIONS
clean_fragment( @fragments )
my $url_title = join("_", clean_fragment("Ümloud vs. ß",'by',"Grégory")); # Umloud_vs._ss_by_Gregory
Returns a cleaned up list of elements. The input elements are expected to be encoded as Unicode strings. Decode them using Encode if you read the fragments as file names from the filesystem.
The operations performed are:
Use Text::Unidecode to downgrade the text from Unicode to 7-bit ASCII.
Eliminate single and double quotes, apostrophes.
Replace all non-letters, non-digits by underscores, including whitespace and control characters.
Squash dashes to a single dash
Squash
_-_
and_-_(-_)+
to -Eliminate leading underscores
Eliminate trailing underscores
Eliminate underscores before - or .
In scalar context, returns the first element of the cleaned up list.
REPOSITORY
The public repository of this module is https://github.com/Corion/text-cleanfragment.
SUPPORT
The public support forum of this module is https://perlmonks.org/.
BUG TRACKER
Please report bugs in this module via the RT CPAN bug queue at https://rt.cpan.org/Public/Dist/Display.html?Name=Text-CleanFragment or via mail to text-cleanfragment-Bugs@rt.cpan.org.
AUTHOR
Max Maischein
corion@cpan.org
COPYRIGHT (c)
Copyright 2012-2019 by Max Maischein
corion@cpan.org
.LICENSE
This module is released under the same terms as Perl itself.
Module Install Instructions
To install Text::CleanFragment, copy and paste the appropriate command in to your terminal.
cpanm Text::CleanFragment
perl -MCPAN -e shell install Text::CleanFragment
For more information on module installation, please visit the detailed CPAN module installation guide.