Browse Source

check for recognized URIs in `pieces add`

Brennen Bearnes 1 year 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
18 18
 
19 19
 =head1 AUTHOR
20 20
 
21
-Brennen Bearnes <bbearnes@gmail.com>
21
+Brennen Bearnes
22 22
 
23 23
 =cut
24 24
 
@@ -30,10 +30,24 @@ use App::Pieces;
30 30
 use Cwd qw(cwd abs_path);
31 31
 use Getopt::Long;
32 32
 use Pod::Usage;
33
+use URI;
33 34
 
34 35
 GetOptions(
35 36
   # 'config=s' => \$config_file,
36 37
   help => sub { pod2usage(0) },
37 38
 ) or pod2usage(2);
38 39
 
39
-App::Pieces->new()->add(@ARGV);
40
+my $p = App::Pieces->new();
41
+
42
+my @addresses;
43
+foreach my $addy (@ARGV) {
44
+  my $uri = URI->new($addy);
45
+  if ($uri->has_recognized_scheme) {
46
+    say "add: " . $uri->canonical;
47
+    push @addresses, $uri->canonical;
48
+  } else {
49
+    say "unrecognized scheme: " . $addy;
50
+  }
51
+}
52
+
53
+$p->add(@addresses);

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

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

+ 1
- 0
test.sh View File

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

+ 2
- 1
testuri.pl View File

@@ -21,9 +21,10 @@ foreach my $sample (@samples) {
21 21
   say "";
22 22
   say $sample . " :::::: ";
23 23
   say "scheme\t" . $u->scheme;
24
-  say "authority\t" . $u->authority;
24
+  # say "authority\t" . $u->authority;
25 25
   say "opaque\t" . $u->opaque;
26 26
   say "path:\t" . $u->path;
27 27
   say "fragment:\t" . $u->fragment;
28 28
   say "recognized?\t" . $u->has_recognized_scheme;
29
+  say "canonical:\t" . $u->canonical;
29 30
 }

Loading…
Cancel
Save