URI-Find-Simple-1.03/ 0000755 0001750 0001750 00000000000 11461230041 012673 5 ustar tomi tomi URI-Find-Simple-1.03/lib/ 0000755 0001750 0001750 00000000000 11461230041 013441 5 ustar tomi tomi URI-Find-Simple-1.03/lib/URI/ 0000755 0001750 0001750 00000000000 11461230041 014100 5 ustar tomi tomi URI-Find-Simple-1.03/lib/URI/Find/ 0000755 0001750 0001750 00000000000 11461230041 014760 5 ustar tomi tomi URI-Find-Simple-1.03/lib/URI/Find/Simple.pm 0000644 0001750 0001750 00000005612 11461227773 016575 0 ustar tomi tomi package URI::Find::Simple;
use warnings;
use strict;
use URI::Find;
use Carp qw(croak);
use Encode qw( encode );
our @ISA = qw( Exporter );
our @EXPORT_OK = qw( list_uris change_uris );
our $VERSION = 1.03;
our $CHARSET = "utf-8";
sub list_uris {
my $text = shift;
croak "expected a text string" unless defined($text);
my @list;
my $uri_find = URI::Find->new( sub {
my ($object, $text) = @_;
push @list, $object->as_string;
return $text;
} );
if ($CHARSET) {
my $copy = encode($CHARSET, $text);
$copy =~ s/([^\000-\177])/'%' . sprintf("%x", ord($1))/eg;
$text = $copy;
}
$uri_find->find(\$text);
return @list;
}
sub change_uris {
my $text = shift;
my $sub = shift;
croak "expected a text string" unless defined($text);
croak "expected a code ref" unless ref($sub) eq 'CODE';
my $uri_find = URI::Find->new( sub {
my ($object, $text) = @_;
return $sub->($object->as_string);
} );
$uri_find->find(\$text);
return $text;
}
1;
__END__
=head1 NAME
URI::Find::Simple - a simple interface to URI::Find
=head1 SYNOPSIS
use URI::Find::Simple qw( list_uris );
my @list = list_uris($text);
my $html = change_uris($text, sub { "$_[0]" } );
=head1 DESCRIPTION
L is all very well, but sometimes you just want a list of the
links in a given piece of text, or you want to change all the urls in
some text somehow, and don't want to mess with callback interfaces.
This module uses URI::Find, but hides the callback interface, providing two
functions - one to list all the uris, and one to change all the uris.
=head2 list_uris( text )
returns a list of all the uris in the passed string, in the form output by
the URI->as_string function, not the form that they exist in the text.
=head2 change_uris( text, sub { code } )
the passed sub is called for every found uri in the text, and it's return
value is substituted into the string. Returns the changed string.
=head1 CAVEATS, BUGS, ETC
The change_uris function is only just nicer than the callback interface. In
some ways it's worse. I's prefer to just pass an s/// operator somehow, but
I don't think that's possible.
The list_uris function returns the stringified versions of the URI objects,
this seemed to be the sensible thing. To present a consistent interface, the
change_uris function operates on these strings as well, which are not the same
as the strings actually present in the original. Therefore this code:
my $text = change_uris($text, sub { shift } );
may not return the same thing you pass it. URIs such as
will be converted to the string 'http://jerakeen.org'.
=head1 SEE ALSO
L, L, L
=head1 AUTHOR
Copyright (c) 2004 Tom Insam inspired by Paul Mison
This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.
URI-Find-Simple-1.03/META.yml 0000644 0001750 0001750 00000000636 11461230041 014151 0 ustar tomi tomi --- #YAML:1.0
name: URI-Find-Simple
version: 1.03
abstract: ~
license: ~
author: ~
generated_by: ExtUtils::MakeMaker version 6.42
distribution_type: module
requires:
Test::More: 0
URI::Find: 0
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html
version: 1.3
URI-Find-Simple-1.03/MANIFEST 0000644 0001750 0001750 00000000241 11461230041 014021 0 ustar tomi tomi lib/URI/Find/Simple.pm
MANIFEST This list of files
t/find.t
Makefile.PL
Changes
META.yml Module meta-data (added by MakeMaker)
URI-Find-Simple-1.03/Changes 0000644 0001750 0001750 00000000505 11461230034 014170 0 ustar tomi tomi Revision history for URI::Title
1.03 2010/10/25
- Package properly
1.01 2010/09/06
- Fix tests for URI::Find change
- Count tests properly
1.01 2008/09/15
- Clearer license
- Better method of requiring perl 5.8.1
1.0 2008/06/19
- Unicode support improved.
0.7 2004/03/16 (Revision 643)
- Initial release
URI-Find-Simple-1.03/t/ 0000755 0001750 0001750 00000000000 11461230041 013136 5 ustar tomi tomi URI-Find-Simple-1.03/t/find.t 0000644 0001750 0001750 00000003300 11461227730 014252 0 ustar tomi tomi use strict;
use warnings;
use lib qw(lib);
use Test::More tests => 16;
use_ok('URI::Find::Simple');
eval { URI::Find::Simple::list_uris() };
ok($@ =~ /expected a text string/, "can't call list_uris without text");
eval { URI::Find::Simple::change_uris() };
ok($@ =~ /expected a text string/, "can't call change_uris without text");
eval { URI::Find::Simple::change_uris('bob') };
ok($@ =~ /expected a code ref/, "can't call change_uris without subref");
ok(my $text = <