Browse Source

check for recognized URIs in `pieces add`

master
Brennen Bearnes 3 years ago
parent
commit
f1b0cb801d
4 changed files with 22 additions and 6 deletions
  1. +16
    -2
      bin/pieces-add
  2. +3
    -3
      lib/App/Pieces.pm
  3. +1
    -0
      test.sh
  4. +2
    -1
      testuri.pl

+ 16
- 2
bin/pieces-add View File

@ -18,7 +18,7 @@ pieces-add - add URLs to the collection of pieces
=head1 AUTHOR
Brennen Bearnes <bbearnes@gmail.com>
Brennen Bearnes
=cut
@ -30,10 +30,24 @@ use App::Pieces;
use Cwd qw(cwd abs_path);
use Getopt::Long;
use Pod::Usage;
use URI;
GetOptions(
# 'config=s' => \$config_file,
help => sub { pod2usage(0) },
) or pod2usage(2);
App::Pieces->new()->add(@ARGV);
my $p = App::Pieces->new();
my @addresses;
foreach my $addy (@ARGV) {
my $uri = URI->new($addy);
if ($uri->has_recognized_scheme) {
say "add: " . $uri->canonical;
push @addresses, $uri->canonical;
} else {
say "unrecognized scheme: " . $addy;
}
}
$p->add(@addresses);

+ 3
- 3
lib/App/Pieces.pm View File

@ -2,7 +2,7 @@
=head1 NAME
App::Pieces - some utility functions for bookmarking and interlinking various things
App::Pieces - some utility functions for bookmarking and interlinking things
=head1 SYNOPSIS
@ -141,7 +141,7 @@ sub add {
# Filter out any paths that have already been marked:
# XXX: This is gonna get pretty silly with thousands of entries to read every
# time.
# time.
my %addressmap = map { $_ => 1 } @addresses;
$self->each_address(sub {
my ($existing_addy) = @_;
@ -158,7 +158,7 @@ sub add {
foreach my $addy (keys %addressmap) {
$sth->execute($addy);
# The empty strings to last_insert_id() should just leave it
# The empty strings passed to last_insert_id() should just leave it
# getting the last insert for the dbh:
push @ids, $self->{dbh}->last_insert_id('', '', '', '');
}


+ 1
- 0
test.sh View File

@ -2,5 +2,6 @@ sudo ./Build install
rm ~/pieces.db
pieces add https://p1k3.com/
pieces add https://squiggle.city/
pieces add foo://bar/
pieces ls
pieces link https://p1k3.com/ https://squiggle.city/

+ 2
- 1
testuri.pl View File

@ -21,9 +21,10 @@ foreach my $sample (@samples) {
say "";
say $sample . " :::::: ";
say "scheme\t" . $u->scheme;
say "authority\t" . $u->authority;
# say "authority\t" . $u->authority;
say "opaque\t" . $u->opaque;
say "path:\t" . $u->path;
say "fragment:\t" . $u->fragment;
say "recognized?\t" . $u->has_recognized_scheme;
say "canonical:\t" . $u->canonical;
}

Loading…
Cancel
Save