Permalink
Browse files

An IRI class might be helpful (RFC 3987)

  • Loading branch information...
1 parent 3c2c497 commit 5d8e5a18d33ba29d54e246de715981d915135adb @gisle gisle committed Oct 25, 2009
Showing with 2,620 additions and 0 deletions.
  1. +41 −0 URI/IRI.pm
  2. +2,579 −0 rfc3987.txt
View
@@ -0,0 +1,41 @@
+package URI::IRI;
+
+use strict;
+use URI ();
+
+use overload '""' => sub { shift->as_string };
+
+sub new {
+ my($class, $uri, $scheme) = @_;
+ return bless {
+ uri => URI->new($uri, $scheme),
+ }, $class;
+}
+
+sub clone {
+ my $self = shift;
+ return bless {
+ uri => $self->{uri}->clone,
+ }, ref($self);
+}
+
+sub as_string {
+ my $self = shift;
+ return $self->{uri}->as_unicode;
+}
+
+sub AUTOLOAD
+{
+ use vars qw($AUTOLOAD);
+ my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2);
+
+ # We create the function here so that it will not need to be
+ # autoloaded the next time.
+ no strict 'refs';
+ *$method = sub { shift->{uri}->$method(@_) };
+ goto &$method;
+}
+
+sub DESTROY {} # avoid AUTOLOADing it
+
+1;
Oops, something went wrong.

0 comments on commit 5d8e5a1

Please sign in to comment.