Acme-Pano-Util
view release on metacpan or search on metacpan
lib/Acme/Pano/Util.pm view on Meta::CPAN
package Acme::Pano::Util;
use 5.006;
use strict;
use encoding 'utf8';
use utf8;
use warnings FATAL => 'all';
use Exporter qw/import/;
our @EXPORT = qw/toBareword fromBareword/;
our @EXPORT_OK = ();
our %EXPORT_TAGS = (
all => [ @EXPORT, @EXPORT_OK ],
);
=head1 NAME
Acme::Pano::Util - Static Utility Methods
=head1 VERSION
Version 0.01
=cut
our $VERSION = '0.011';
=head1 SYNOPSIS
This module provides various random utilities that Pano Papadatos made.
=head1 EXPORT
toBareword - Converts any string to a string with only letters, underscores and numbers that does not start with a number (bareword)
fromBareword - Converts a string that was returned using toBareword back to its original form
=head1 SUBROUTINES/METHODS
=head2 toBareword
Usage: converts any string to a string with only letters, underscores and numbers that does not start with a number (bareword)
Arguments: (0) the string to convert
Returns: the converted string
Conversion Method
- A single underscore is converted into 2 _s
- A single zero is converted into 2 0s
- A number is converted into _number (To catch things that start with numbers)
- Any non [a-zA-Z] character is converted into _0_ plus its numeric value (ord) (e.g. _123)
=cut
sub toBareword {
my ($string) = @_;
return if(!defined($string));
$string =~ s/_/__/g;
$string =~ s/0/00/g;
$string =~ s/([0-9]+)/_$1/g;
$string =~ s/([^a-zA-Z0-9_]+)/join('',map {'_0_'.ord($_)} split('',$1))/eg;
( run in 0.813 second using v1.01-cache-2.11-cpan-e1769b4cff6 )