Greetings,

It would be very nice to have recognition of the Gemini protocol when parsing URIs.

Here is my guess at how it could go.

$ 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";
and in lib/URI/gemini.pm it could be something like this:
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;

For that to be considered for addition, can I just throw it over the fence here?


In reply to Adding recognition of Gemini to URI.pm? by mldvx4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.