$ git diff diff --git a/lib/URI/Heuristic.pm b/lib/URI/Heuristic.pm index 1780f34..4694813 100644 --- a/lib/URI/Heuristic.pm +++ b/lib/URI/Heuristic.pm @@ -155,7 +155,7 @@ sub uf_uristr ($) if (/^(www|web|home)[a-z0-9-]*(?:\.|$)/i) { $_ = "http://$_"; - } elsif (/^(ftp|gopher|news|wais|https|http)[a-z0-9-]*(?:\.|$)/i) { + } elsif (/^(ftp|gemini|gopher|news|wais|https|http)[a-z0-9-]*(?:\.|$)/i) { $_ = lc($1) . "://$_"; } elsif ($^O ne "MacOS" && @@ -168,7 +168,7 @@ sub uf_uristr ($) } elsif ($^O eq "MacOS" && m/:/) { # potential MacOS file name - unless (m/^(ftp|gopher|news|wais|http|https|mailto):/) { + unless (m/^(ftp|gemini|gopher|news|wais|http|https|mailto):/) { require URI::file; my $a = URI::file->new($_)->as_string; $_ = ($a =~ m/^file:/) ? $a : "file:$a"; #### package URI::gemini; # https://geminiprotocol.net/ use strict; use warnings; our $VERSION = '0.1'; use parent 'URI::_server'; use URI::Escape qw(uri_unescape); sub default_port { 1965 } sub _gemini_type { my $self = shift; my $path = $self->path_query; $path =~ s,^/,,; my $gtype = $1 if $path =~ s/^(.)//s; if (@_) { my $new_type = shift; if (defined($new_type)) { Carp::croak("Bad gemini type '$new_type'") unless length($new_type) == 1; substr($path, 0, 0) = $new_type; $self->path_query($path); } else { Carp::croak("Can't delete gemini type when selector is present") if length($path); $self->path_query(undef); } } return $gtype; } sub gemini_type { my $self = shift; my $gtype = $self->_gemini_type(@_); $gtype = "1" unless defined $gtype; $gtype; } sub gtype { goto &gemini_type } # URI::URL compatibility sub selector { shift->_gfield(0, @_) } sub search { shift->_gfield(1, @_) } sub string { shift->_gfield(2, @_) } sub _gfield { my $self = shift; my $fno = shift; my $path = $self->path_query; $path =~ s/\?/\t/; $path = uri_unescape($path); $path =~ s,^/,,; my $gtype = $1 if $path =~ s,^(.),,s; my @path = split(/\t/, $path, 3); if (@_) { # modify my $new = shift; $path[$fno] = $new; pop(@path) while @path && !defined($path[-1]); for (@path) { $_="" unless defined } $path = $gtype; $path = "1" unless defined $path; $path .= join("\t", @path); $self->path_query($path); } $path[$fno]; } 1;