URI::Encode (3)
Leading comments
Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) Standard preamble: ========================================================================
NAME
URI::Encode - Simple percent Encoding/DecodingSYNOPSIS
# OOP Interface use URI::Encode; my $uri = URI::Encode->new( { encode_reserved => 0 } ); my $encoded = $uri->encode($data); my $decoded = $uri->decode($encoded); # Functional use URI::Encode qw(uri_encode uri_decode); my $encoded = uri_encode($data); my $decoded = uri_decode($encoded);
DESCRIPTION
This modules provides simpleThe main purpose of this module (at least for me) was to provide an easy method to encode strings (mainly URLs) into a format which can be pasted into a plain text emails, and that those links are 'click-able' by the person reading that email. This can be accomplished by
This module can also be useful when using HTTP::Tiny to ensure the URLs are properly escaped.
This module does not encode reserved characters by default. If you are looking for speed and want to encode reserved characters, use URI::Escape::XS
See this script <github.com/mithun/perl-uri-encode/raw/master/.author/benchmark.pl> for a comparison on encoding results and performance.
METHODS
new()
Creates a new object, no arguments are required
my $encoder = URI::Encode->new(\%options);
The following options can be passed to the constructor
- encode_reserved
-
my $encoder = URI::Encode->new({encode_reserved => 0});
If true, ``Reserved Characters'' are also encoded. Defaults to false.
- double_encode
-
my $encoder = URI::Encode->new({double_encode => 1});
If false, characters that are already percent-encoded will not be encoded again. Defaults to true.
my $encoder = URI::Encode->new({double_encode => 0}); print $encoder->encode('perl.com/foo%20bar'); # prints perl.com/foo%20bar
encode($url, \%options)
This method encodes the
$uri->encode("perl.com/foo bar"); $uri->encode( "perl.com/foo bar", { encode_reserved => 1 } );
decode($url)
This method decodes a 'percent' encoded
$uri->decode("http%3A%2F%2Fperl.com%2Ffoo%20bar");
EXPORTED FUNCTIONS
The following functions are exported upon request. This provides a non-OOP interface- uri_encode($url, \%options)
- uri_decode($url)
CHARACTER CLASSES
Reserved Characters
The following characters are considered as reserved (
! * ' ( ) ; : @ & = + $ , / ? # [ ]
Unreserved Characters
The following characters are considered as Unreserved. They will not be encoded
a-z A-Z 0-9 - _ . ~
DEPENDENCIES
EncodeACKNOWLEDGEMENTS
Gisle Aas for URI::EscapeDavid Nicol for Tie::UrlEncoder
SEE ALSO
URI::Escape
URI::Escape::XS
URI::Escape::JavaScript
Tie::UrlEncoder
BUGS AND LIMITATIONS
Please report any bugs or feature requests at <github.com/mithun/perl-uri-encode/issues>AUTHOR
Mithun Ayachit "mithun@cpan.org"LICENSE AND COPYRIGHT
Copyright (c) 2014, Mithun Ayachit. All rights reserved.This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.