Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/blib/
/.build/
_build/
cover_db/
inc/
Build
!Build/
Build.bat
.last_cover_stats
/Makefile
/Makefile.old
/MANIFEST.bak
/MYMETA.*
nytprof.out
/pm_to_blib
*.o
*.bs
/_eumm/
/URL-Encode-*
9 changes: 9 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changes
lib/URL/Encode.pm
lib/URL/Encode.pod
lib/URL/Encode/PP.pm
Makefile.PL
MANIFEST This list of files
README
t/010_basic.t
t/020_params.t
75 changes: 75 additions & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

#!start included /home/grinnz/.plenv/versions/5.28.0/lib/perl5/site_perl/5.28.0/ExtUtils/MANIFEST.SKIP
# Avoid version control files.
\bRCS\b
\bCVS\b
\bSCCS\b
,v$
\B\.svn\b
\B\.git\b
\B\.gitignore\b
\b_darcs\b
\B\.cvsignore$

# Avoid VMS specific MakeMaker generated files
\bDescrip.MMS$
\bDESCRIP.MMS$
\bdescrip.mms$

# Avoid Makemaker generated and utility files.
\bMANIFEST\.bak
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib\.ts$
\bpm_to_blib$
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
\b_eumm/ # 7.05_05 and above

# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
\bBuild.bat$
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$

# and Module::Build::Tiny generated files
\b_build_params$

# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
\.tmp$
\.#
\.rej$
\..*\.sw.?$

# Avoid OS-specific files/dirs
# Mac OSX metadata
\B\.DS_Store
# Mac OSX SMB mount metadata files
\B\._

# Avoid Devel::Cover and Devel::CoverX::Covered files.
\bcover_db\b
\bcovered\b

# Avoid prove files
\B\.prove$

# Avoid MYMETA files
^MYMETA\.

# Avoid travis-ci.org file
^\.travis.yml

# Avoid appveyor.com file
^\.appveyor.yml
#!end included /home/grinnz/.plenv/versions/5.28.0/lib/perl5/site_perl/5.28.0/ExtUtils/MANIFEST.SKIP

^URL-Encode-
^MANIFEST\.SKIP
57 changes: 43 additions & 14 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
use strict;
use inc::Module::Install;
use warnings;
use 5.008001;
use ExtUtils::MakeMaker;

name 'URL-Encode';
perl_version '5.008001';
all_from 'lib/URL/Encode.pm';
repository 'http://github.com/chansen/p5-url-encode';
readme_from 'lib/URL/Encode.pod';
my %WriteMakefileArgs = (
ABSTRACT_FROM => 'lib/URL/Encode.pod',
AUTHOR => 'Christian Hansen <chansen@cpan.org>',
LICENSE => 'perl_5',
META_MERGE => {
dynamic_config => 0,
'meta-spec' => {version => 2},
resources => {
repository => {
type => 'git',
url => 'http://github.com/chansen/p5-url-encode.git',
web => 'http://github.com/chansen/p5-url-encode',
},
},
},
MIN_PERL_VERSION => '5.008001',
NAME => 'URL::Encode',
PREREQ_PM => {
'Carp' => '0',
'Exporter' => '0',
},
TEST_REQUIRES => {
'Test::More' => '0.88',
},
VERSION_FROM => 'lib/URL/Encode.pm',
test => {TESTS => 't/*.t t/*/*.t'},
);

requires 'Carp' => '0';
requires 'Exporter' => '0';
requires 'XSLoader' => '0';
test_requires 'Test::More' => '0.88';
makemaker_args INC => '-I.';
unless (eval { ExtUtils::MakeMaker->VERSION('6.64') }) {
my $test_requires = delete $WriteMakefileArgs{TEST_REQUIRES};
@{$WriteMakefileArgs{PREREQ_PM}}{keys %$test_requires} = values %$test_requires;
}

tests 't/*.t t/*/*.t';

WriteAll;
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION('6.52') };
delete $WriteMakefileArgs{MIN_PERL_VERSION}
unless eval { ExtUtils::MakeMaker->VERSION('6.48') };
delete $WriteMakefileArgs{META_MERGE}
unless eval { ExtUtils::MakeMaker->VERSION('6.46') };
delete $WriteMakefileArgs{LICENSE}
unless eval { ExtUtils::MakeMaker->VERSION('6.31') };

WriteMakefile(%WriteMakefileArgs);
180 changes: 180 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
NAME
URL::Encode - Encoding and decoding of
"application/x-www-form-urlencoded" encoding.

SYNOPSIS
$octets = url_decode($octets);
$string = url_decode_utf8($octets);

$octets = url_encode($octets);
$octets = url_encode_utf8($string);

$params = url_params_flat($octets [, $utf8 = false]);
$params = url_params_mixed($octets [, $utf8 = false]);
$params = url_params_multi($octets [, $utf8 = false]);
url_params_each($octets, $callback [, $utf8 = false]);

DESCRIPTION
This module provides functions to encode and decode strings into and
from the "application/x-www-form-urlencoded" encoding.

The "application/x-www-form-urlencoded" format encodes a ordered data
sets of pairs consisting of a name and a value, with pairs seperated by
ampersand or semicolon and names and values seperated by the equal sign.
Space characters are replaced with plus sign and any characters not in
the unreserved character set is encoded using the percent-encoding
scheme also used for resource identifiers. A percent-encoded octet is
encoded as a character triplet, consisting of the percent character "%"
followed by the two hexadecimal digits representing that octet's numeric
value.

The unreserved character set includes the uppercase and lowercase
letters, decimal digits, hyphen, period, underscore, and tilde.

ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789
- . _ ~

FUNCTIONS
url_decode
$octets = url_decode($octets);

Returns a decoded representation of the given URL-encoded $octets as an
octet string.

url_decode_utf8
$string = url_decode_utf8($octets);

Returns a decoded representation of the given URL-encoded $octets in
UTF-8 encoding as a character string.

url_encode
$octets = url_encode($octets);

Returns a URL-encoded representation of the given $octets as an octet
string.

url_encode_utf8
$octets = url_encode_utf8($string);

Returns a URL-encoded representation of $string in UTF-8 encoding as an
octet string.

url_params_flat
$params = url_params_flat($octets);
$params = url_params_flat($octets, $utf8);

Parses a URL-encoded data set of name/value pairs from the given octets.
Returns an ARRAY reference containing the URL-decoded name/value pairs
in order.

$params = url_params_flat('foo=A&foo=B&bar=C');
$params; # [ foo => 'A', foo => 'B', bar => 'C' ]

url_params_mixed
$params = url_params_mixed($octets);
$params = url_params_mixed($octets, $utf8);

Parses a URL-encoded data set of name/value pairs from the given octets.
Returns a HASH reference containing the URL-decoded name/value pairs.
Multiple occurrences of a parameter will result in an ARRAY reference
holding all the values for that parameter in order.

$params = url_params_mixed('foo=A&foo=B&bar=C');
$params; # { foo => [ 'A', 'B' ], bar => 'C' }

url_params_multi
$params = url_params_multi($octets);
$params = url_params_multi($octets, $utf8);

Parses a URL-encoded data set of name/value pairs from the given octets.
Returns a HASH reference containing the URL-decoded name/value pairs.
Values are stored in an ARRAY reference.

$params = url_params_multi('foo=A&foo=B&bar=C');
$params; # { foo => [ 'A', 'B' ], bar => [ 'C' ] }

url_params_each
url_params_each($octets, $callback);
url_params_each($octets, $callback, $utf8);

Parses a URL-encoded data set of name/value pairs from the given octets.
Invokes the given callback for each URL-decoded name/value pair.

$callback = sub {
my ($name, $value) = @_;
};

url_params_each($octets, $callback);

EXPORTS
None by default. All functions can be exported using the ":all" tag or
individually.

DIAGNOSTICS
(F) Usage: %s
Subroutine called with wrong number of arguments.

(F) Wide character in octet string
(F) Malformed UTF-8 in URL-decoded octets

PERFORMANCE
The URL::Encode::XS module provides faster C/XS implementations of the
functions found in this module. This module will automatically use
URL::Encode::XS if it's installed.

Benchmarking url_decode() PP vs XS:

Rate PP XS
PP 507520/s -- -92%
XS 6389812/s 1159% --

Benchmarking url_encode() PP vs XS:

Rate PP XS
PP 119866/s -- -98%
XS 7214089/s 5918% --

Benchmarking url_params_mixed() PP vs XS:

Rate PP XS
PP 4450/s -- -95%
XS 95015/s 2035% --

Benchmarking URL::Encode::XS vs CGI::Deurl::XS

Rate CGI::Deurl::XS URL::Encode::XS
CGI::Deurl::XS 51932/s -- -48%
URL::Encode::XS 99444/s 91% --

SEE ALSO
URL::Encode::XS
XS implementation of "URL::Encode".

CGI::Deurl::XS

SUPPORT
BUGS
Please report any bugs by email to "bug-url-encode at rt.cpan.org", or
through the web interface at
<http://rt.cpan.org/Public/Dist/Display.html?Name=URL-Encode>. You will
be automatically notified of any progress on the request by the system.

SOURCE CODE
This is open source software. The code repository is available for
public review and contribution under the terms of the license.

<http://github.com/chansen/p5-url-encode>

git clone http://github.com/chansen/p5-url-encode

AUTHOR
Christian Hansen <chansen@cpan.org>

COPYRIGHT
Copyright 2011-2014 by Christian Hansen.

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

2 changes: 1 addition & 1 deletion lib/URL/Encode.pod
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ L<http://github.com/chansen/p5-url-encode>

=head1 AUTHOR

Christian Hansen C<chansen@cpan.org>
Christian Hansen <chansen@cpan.org>

=head1 COPYRIGHT

Expand Down