Any-URI-Escape

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

NAME
    Any::URI::Escape - Load URI::Escape::XS preferentially over URI::Escape

SYNOPSIS
      use Any::URI::Escape;
      $escaped_url = uri_escape($url);

      # URI::Escape::XS will be used instead of URI::Escape if it is installed.

DESCRIPTION
    URI::Escape is great, but URI::Escape::XS is faster. This module loads
    URI::Escape::XS and imports the two most common methods if XS is
    installed.

    The insides of this module aren't completely shaken out yet, so patches
    welcome.

lib/Any/URI/Escape.pm  view on Meta::CPAN


our $VERSION = 0.01;

=head1 NAME

Any::URI::Escape - Load URI::Escape::XS preferentially over URI::Escape

=cut

use base 'Exporter';
our @EXPORT = qw( uri_escape uri_unescape );

BEGIN {

    eval 'require URI::Escape::XS';

    my $pkg;
    if ($@) {

        # xs version not installed, use URI::Escape
        require URI::Escape;
        $pkg = 'URI::Escape';

    }
    else {

        $pkg = 'URI::Escape::XS';
    }
    no strict 'refs';
    my $class = __PACKAGE__;
    *{"$class\::uri_escape"} = *{"$pkg\::uri_escape"};
    *{"$class\::uri_unescape"} = *{"$pkg\::uri_unescape"};
}


1;

=head1 SYNOPSIS

  use Any::URI::Escape;
  $escaped_url = uri_escape($url);

  # URI::Escape::XS will be used instead of URI::Escape if it is installed.

=head1 DESCRIPTION

URI::Escape is great, but URI::Escape::XS is faster.  This module loads
URI::Escape::XS and imports the two most common methods if XS is installed.

The insides of this module aren't completely shaken out yet, so patches
welcome.

t/Any-URI-Escape.t  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More tests => 4;
BEGIN { use_ok('Any::URI::Escape') }

can_ok('Any::URI::Escape', qw( uri_escape uri_unescape ));

cmp_ok(uri_escape("http://foo.com"), 'eq', 'http%3A%2F%2Ffoo.com');
cmp_ok(uri_unescape("http%3A%2F%2Ffoo.com"), 'eq', 'http://foo.com');



( run in 1.502 second using v1.01-cache-2.11-cpan-c21f80fb71c )