| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::rdfns; | 
| 2 | 1 |  |  | 1 |  | 65519 | use v5.10; | 
|  | 1 |  |  |  |  | 11 |  | 
| 3 | 1 |  |  | 1 |  | 10 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 410 | use RDF::NS; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 695 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '20181102'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub new { | 
| 11 | 8 |  |  | 8 | 0 | 5856 | bless {}, shift; | 
| 12 |  |  |  |  |  |  | } | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub run { | 
| 15 | 8 |  |  | 8 | 0 | 25 | my ($self, @ARGV) = @_; | 
| 16 | 8 |  |  |  |  | 13 | my $format = ''; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 8 | 50 | 33 |  |  | 72 | return $self->usage if !@ARGV or $ARGV[0] =~ /^(-[?h]|--help)$/; | 
| 19 | 8 | 50 |  |  |  | 27 | return $self->version if $ARGV[0] =~ /^(-v|--version)$/; | 
| 20 | 8 | 50 |  |  |  | 22 | return $self->dates if $ARGV[0] eq '--dates'; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 8 |  |  |  |  | 35 | my $ns = RDF::NS->new; | 
| 23 | 8 |  |  |  |  | 44 | my $sn = $ns->REVERSE; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 8 |  |  |  |  | 45 | foreach my $a (@ARGV) { | 
| 26 | 11 | 100 |  |  |  | 50 | if ( $a =~ /^([0-9]{8})$/ ) { | 
| 27 | 2 |  |  |  |  | 13 | $ns = RDF::NS->new($a); | 
| 28 | 2 |  |  |  |  | 12 | $sn = $ns->REVERSE; | 
| 29 | 2 |  |  |  |  | 8 | next; | 
| 30 |  |  |  |  |  |  | } | 
| 31 | 9 | 100 |  |  |  | 123 | if ( $a =~ qr{^https?://} ) { | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 32 | 4 |  |  |  |  | 20 | my $qname = $sn->qname($a); | 
| 33 | 4 | 100 |  |  |  | 11 | if ($qname) { | 
| 34 | 2 |  |  |  |  | 10 | $qname =~ s/:$//; | 
| 35 | 2 |  |  |  |  | 10 | say $qname; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  | } elsif ( $a =~ /:/ ) { | 
| 38 | 0 |  |  |  |  | 0 | print map { $ns->URI($_)."\n" } split(/[|, ]+/, $a); | 
|  | 0 |  |  |  |  | 0 |  | 
| 39 |  |  |  |  |  |  | } elsif ( $a =~ s/\.([^.]+)$// ) { | 
| 40 | 2 |  |  |  |  | 37 | my $f = $1; | 
| 41 | 2 | 100 |  |  |  | 19 | if ( $f eq 'prefix' ) { | 
|  |  | 50 |  |  |  |  |  | 
| 42 | 1 | 50 |  |  |  | 10 | print map { "$_\n" if defined $_ } map { | 
| 43 | 1 |  |  |  |  | 4 | $sn->{$_} | 
|  | 1 |  |  |  |  | 3 |  | 
| 44 |  |  |  |  |  |  | } $ns->FORMAT( $format, $a ); | 
| 45 | 1 |  |  |  |  | 222 | next; | 
| 46 |  |  |  |  |  |  | } elsif ( $f =~ $RDF::NS::FORMATS ) { | 
| 47 | 1 |  |  |  |  | 3 | $format = $f; | 
| 48 |  |  |  |  |  |  | } else { | 
| 49 | 0 |  |  |  |  | 0 | print STDERR "Unknown format: $f\n"; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | } | 
| 52 | 8 | 100 |  |  |  | 39 | if ( lc($format) eq 'json' ) { | 
| 53 | 1 |  |  |  |  | 6 | say join ",\n", $ns->FORMAT( $format, $a ); | 
| 54 |  |  |  |  |  |  | } else { | 
| 55 | 7 |  |  |  |  | 27 | say $_ for $ns->FORMAT( $format, $a ); | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub usage { | 
| 61 | 0 |  |  | 0 | 0 |  | print <<'USAGE'; | 
| 62 |  |  |  |  |  |  | USAGE: rdfns { [YYYYMMDD] ( [.format] | prefix:name | URL ) }+ | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | formats: txt, sparql, ttl, n3, xmlns, json, beacon, prefix | 
| 65 |  |  |  |  |  |  | options: --help | --version | --dates | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | examples: | 
| 68 |  |  |  |  |  |  | rdfns 20111102 foaf,owl.ttl | 
| 69 |  |  |  |  |  |  | rdfns foaf.xmlns foaf.n3 | 
| 70 |  |  |  |  |  |  | rdfns rdfs:seeAlso | 
| 71 |  |  |  |  |  |  | rdfns http://www.w3.org/2003/01/geo/wgs84_pos# | 
| 72 |  |  |  |  |  |  | rdfns http://purl.org/dc/elements/1.1/title | 
| 73 |  |  |  |  |  |  | rdfns wgs.prefix | 
| 74 |  |  |  |  |  |  | USAGE | 
| 75 | 0 |  |  |  |  |  | 0; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub version { | 
| 79 | 0 |  |  | 0 | 0 |  | print $RDF::NS::VERSION . "\n"; | 
| 80 | 0 |  |  |  |  |  | 0; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub dates { | 
| 84 | 0 |  |  | 0 | 0 |  | my $fh = RDF::NS->new->DATA; | 
| 85 | 0 |  |  |  |  |  | my $date = ''; | 
| 86 | 0 |  |  |  |  |  | foreach (<$fh>) { | 
| 87 | 0 |  |  |  |  |  | chomp; | 
| 88 | 0 | 0 |  |  |  |  | next if /^#/; | 
| 89 | 0 |  |  |  |  |  | my @fields = split "\t", $_; | 
| 90 | 0 | 0 |  |  |  |  | if ($fields[2] ne $date) { | 
| 91 | 0 |  |  |  |  |  | say $date=$fields[2]; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  | } | 
| 94 | 0 |  |  |  |  |  | 0; | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | 1; | 
| 98 |  |  |  |  |  |  | __END__ |