Subject: | Wishlist: non-global way to turn on URI::URL strictness |
It would be handy for those using URI::URL to validate URLs if there
were a non-global alternative to URI::URL::strict(). As things stand,
validation without action at a distance seems to involve code like
my $old_strict = URI::URL::strict( 1 );
my $obj = eval {
URI::URL->new( $url );
} or do {
URI::URL::strict( $old_strict );
die $@; # Re-raise exception
};
URI::URL::strict( $old_strict );
There are a number of ways to get what I would like. The following list
is off the top of my head, and is in no particular order, though I think
if I could have anything I wanted, I would actually prefer the last
suggestion.
Documenting $URI::URL::STRICT would allow the strictness to be
localized, and reduce the above code to
my $obj = do {
local $URI::URL::STRICT = 1;
URI::URL->new( $url );
};
Making it an argument to new() would also be okay, making the code
something like
my $obj = URI::URL->new( $url, strict => 1 );
Yet another acceptable alternative would be an is_known_scheme() method
on the returned object, which (speaking in terms of the internals,
assuming I understand them) returns a false value for URI::_foreign
objects, and a true value for anything else.