blib/lib/Acme/Pano/Util.pm

filter: Statementstmt 100% 8 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 11 / 11 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package Acme::Pano::Util;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use encoding 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use utf8;
7 use warnings FATAL => 'all';
8 use Exporter qw/import/;
9 our @EXPORT = qw/toBareword fromBareword/;
10 our @EXPORT_OK = ();
11 our %EXPORT_TAGS = (
12 all => [ @EXPORT, @EXPORT_OK ],
13 );
14  
15 =head1 NAME
16  
17 Acme::Pano::Util - Static Utility Methods
18  
19 =head1 VERSION
20  
21 Version 0.01
22  
23 =cut
24  
25 our $VERSION = '0.011';
26  
27  
28 =head1 SYNOPSIS
29  
30 This module provides various random utilities that Pano Papadatos made.
31  
32 =head1 EXPORT
33  
34 toBareword - Converts any string to a string with only letters, underscores and numbers that does not start with a number (bareword)
35  
36 fromBareword - Converts a string that was returned using toBareword back to its original form
37  
38 =head1 SUBROUTINES/METHODS
39  
40 =head2 toBareword
41  
42 Usage: converts any string to a string with only letters, underscores and numbers that does not start with a number (bareword)
43  
44 Arguments: (0) the string to convert
45  
46 Returns: the converted string
47  
48 Conversion Method
49  
50 - A single underscore is converted into 2 _s
51  
52 - A single zero is converted into 2 0s
53  
54 - A number is converted into _number (To catch things that start with numbers)
55  
56 - Any non [a-zA-Z] character is converted into _0_ plus its numeric value (ord) (e.g. _123)
57  
58 =cut
59  
60 sub toBareword {
61 my ($string) = @_;
62 return if(!defined($string));
63 $string =~ s/_/__/g;
64 $string =~ s/0/00/g;
65 $string =~ s/([0-9]+)/_$1/g;
66 $string =~ s/([^a-zA-Z0-9_]+)/join('',map {'_0_'.ord($_)} split('',$1))/eg;
67 return $string;
68 }
69  
70 =head2 fromBareword
71  
72 Usage: converts any string that was returned using "toBareword" back to its original form
73  
74 Arguments: (0) the string to convert
75  
76 Returns: the converted string
77  
78 =cut
79  
80 sub fromBareword{
81 my ($string) = @_;
82 return if(!defined($string));
83 $string =~ s/_0_([0-9]+)/chr($1)/eg;
84 $string =~ s/_([0-9]+)/$1/g;
85 $string =~ s/00/0/g;
86 $string =~ s/__/_/g;
87 return $string;
88 }
89  
90 =head1 AUTHOR
91  
92 Pano Papadatos, C<< <pano at heypano.com> >>
93  
94 =head1 BUGS
95  
96 Please report any bugs or feature requests to C<bug-acme-pano-util at rt.cpan.org>, or through
97 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-Pano-Util>. I will be notified, and then you'll
98 automatically be notified of progress on your bug as I make changes.
99  
100  
101  
102  
103 =head1 SUPPORT
104  
105 You can find documentation for this module with the perldoc command.
106  
107 perldoc Acme::Pano::Util
108  
109  
110 You can also look for information at:
111  
112 =over 4
113  
114 =item * RT: CPAN's request tracker (report bugs here)
115  
116 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Acme-Pano-Util>
117  
118 =item * AnnoCPAN: Annotated CPAN documentation
119  
120 L<http://annocpan.org/dist/Acme-Pano-Util>
121  
122 =item * CPAN Ratings
123  
124 L<http://cpanratings.perl.org/d/Acme-Pano-Util>
125  
126 =item * Search CPAN
127  
128 L<http://search.cpan.org/dist/Acme-Pano-Util/>
129  
130 =back
131  
132  
133 =head1 ACKNOWLEDGEMENTS
134  
135  
136 =head1 LICENSE AND COPYRIGHT
137  
138 Copyright 2013 Pano Papadatos.
139  
140 This program is free software; you can redistribute it and/or modify it
141 under the terms of the the Artistic License (2.0). You may obtain a
142 copy of the full license at:
143  
144 L<http://www.perlfoundation.org/artistic_license_2_0>
145  
146 Any use, modification, and distribution of the Standard or Modified
147 Versions is governed by this Artistic License. By using, modifying or
148 distributing the Package, you accept this license. Do not use, modify,
149 or distribute the Package, if you do not accept this license.
150  
151 If your Modified Version has been derived from a Modified Version made
152 by someone other than you, you are nevertheless required to ensure that
153 your Modified Version complies with the requirements of this license.
154  
155 This license does not grant you the right to use any trademark, service
156 mark, tradename, or logo of the Copyright Holder.
157  
158 This license includes the non-exclusive, worldwide, free-of-charge
159 patent license to make, have made, use, offer to sell, sell, import and
160 otherwise transfer the Package with respect to any patent claims
161 licensable by the Copyright Holder that are necessarily infringed by the
162 Package. If you institute patent litigation (including a cross-claim or
163 counterclaim) against any party alleging that the Package constitutes
164 direct or contributory patent infringement, then this Artistic License
165 to you shall terminate on the date that such litigation is filed.
166  
167 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
168 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
169 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
170 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
171 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
172 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
173 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
174 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
175  
176  
177 =cut
178  
179 1; # End of Acme::Pano::Util
↑ Summary