| 1 | package App::rdfnsscip-perl cpan RDF-NS 20230619 App/rdfns/; |
| 2 | use v5.10scip-perl cpan RDF-NS 20230619 `v5.10`/; |
| 3 | use strictscip-perl cpan RDF-NS 20230619 strict/; |
| 4 | use warningsscip-perl cpan RDF-NS 20230619 warnings/; |
| 5 | |
| 6 | use RDF::NSscip-perl cpan RDF-NS 20230619 RDF/NS/; |
| 7 | |
| 8 | our $VERSIONscip-perl cpan RDF-NS 20230619 App/rdfns/$VERSION. = '20230619'; |
| 9 | |
| 10 | sub newscip-perl cpan RDF-NS 20230619 App/rdfns/new(). { |
| 11 | blessscip-perl cpan RDF-NS 20230619 App/rdfns/bless(). {}, shiftscip-perl cpan RDF-NS 20230619 App/rdfns/shift().; |
| 12 | } |
| 13 | |
| 14 | sub runscip-perl cpan RDF-NS 20230619 App/rdfns/run(). { |
| 15 | my ($self, @ARGV) = @_scip-perl cpan RDF-NS 20230619 App/rdfns/`@_`.; |
| 16 | my $format = ''; |
| 17 | |
| 18 | return $self->usagescip-perl cpan RDF-NS 20230619 App/rdfns/usage(). if !@ARGV or $ARGV[0] =~ /^(-[?h]|--help)$/; |
| 19 | return $self->versionscip-perl cpan RDF-NS 20230619 App/rdfns/version(). if $ARGV[0] =~ /^(-v|--version)$/; |
| 20 | return $self->datesscip-perl cpan RDF-NS 20230619 App/rdfns/dates(). if $ARGV[0] eq '--dates'; |
| 21 | |
| 22 | my $ns = RDF::NS->newscip-perl cpan RDF-NS 20230619 RDF/NS/new().; |
| 23 | my $sn = $ns->REVERSEscip-perl cpan RDF-NS 20230619 RDF/NS/REVERSE().; |
| 24 | |
| 25 | foreach my $a (@ARGV) { |
| 26 | if ( $a =~ /^([0-9]{8})$/ ) { |
| 27 | $ns = RDF::NS->newscip-perl cpan RDF-NS 20230619 RDF/NS/new().($a); |
| 28 | $sn = $ns->REVERSEscip-perl cpan RDF-NS 20230619 RDF/NS/REVERSE().; |
| 29 | next; |
| 30 | } |
| 31 | if ( $a =~ qr{^https?://} ) { |
| 32 | my $qname = $sn->qnamescip-perl cpan RDF-NS 20230619 App/rdfns/qname().($a); |
| 33 | if ($qname) { |
| 34 | $qname =~ s/:$//; |
| 35 | sayscip-perl cpan RDF-NS 20230619 App/rdfns/say(). $qname; |
| 36 | } |
| 37 | } elsif ( $a =~ /:/ ) { |
| 38 | printscip-perl cpan RDF-NS 20230619 App/rdfns/print(). mapscip-perl cpan RDF-NS 20230619 App/rdfns/map(). { $ns->URIscip-perl cpan RDF-NS 20230619 RDF/NS/URI().($_scip-perl cpan RDF-NS 20230619 App/rdfns/$_.)."\n" } splitscip-perl cpan RDF-NS 20230619 App/rdfns/split().(/[|, ]+/, $a); |
| 39 | } elsif ( $a =~ s/\.([^.]+)$// ) { |
| 40 | my $f = $1scip-perl cpan RDF-NS 20230619 App/rdfns/$1.; |
| 41 | if ( $f eq 'prefix' ) { |
| 42 | printscip-perl cpan RDF-NS 20230619 App/rdfns/print(). mapscip-perl cpan RDF-NS 20230619 App/rdfns/map(). { "$_\n" if definedscip-perl cpan RDF-NS 20230619 App/rdfns/defined(). $_scip-perl cpan RDF-NS 20230619 App/rdfns/$_. } mapscip-perl cpan RDF-NS 20230619 App/rdfns/map(). { |
| 43 | $sn->{$_scip-perl cpan RDF-NS 20230619 App/rdfns/$_.} |
| 44 | } $ns->FORMATscip-perl cpan RDF-NS 20230619 RDF/NS/FORMAT().( $format, $a ); |
| 45 | next; |
| 46 | } elsif ( $f =~ $RDF::NS::FORMATSscip-perl cpan RDF-NS 20230619 RDF/NS/$FORMATS. ) { |
| 47 | $format = $f; |
| 48 | } else { |
| 49 | print STDERR "Unknown format: $f\n"; |
| 50 | } |
| 51 | } |
| 52 | if ( lcscip-perl cpan RDF-NS 20230619 App/rdfns/lc().($format) eq 'json' ) { |
| 53 | sayscip-perl cpan RDF-NS 20230619 App/rdfns/say(). joinscip-perl cpan RDF-NS 20230619 App/rdfns/join(). ",\n", $ns->FORMATscip-perl cpan RDF-NS 20230619 RDF/NS/FORMAT().( $format, $a ); |
| 54 | } else { |
| 55 | sayscip-perl cpan RDF-NS 20230619 App/rdfns/say(). $_scip-perl cpan RDF-NS 20230619 App/rdfns/$_. for $ns->FORMATscip-perl cpan RDF-NS 20230619 RDF/NS/FORMAT().( $format, $a ); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | sub usagescip-perl cpan RDF-NS 20230619 App/rdfns/usage(). { |
| 61 | printscip-perl cpan RDF-NS 20230619 App/rdfns/print(). <<'USAGE'; |
| 62 | USAGE: rdfns { [YYYYMMDD] ( <prefix[es]>[.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; |
| 76 | } |
| 77 | |
| 78 | sub versionscip-perl cpan RDF-NS 20230619 App/rdfns/version(). { |
| 79 | printscip-perl cpan RDF-NS 20230619 App/rdfns/print(). $RDF::NS::VERSIONscip-perl cpan RDF-NS 20230619 RDF/NS/$VERSION. . "\n"; |
| 80 | 0; |
| 81 | } |
| 82 | |
| 83 | sub datesscip-perl cpan RDF-NS 20230619 App/rdfns/dates(). { |
| 84 | my $fh = RDF::NS->newscip-perl cpan RDF-NS 20230619 RDF/NS/new().->DATAscip-perl cpan RDF-NS 20230619 App/rdfns/DATA().; |
| 85 | my $date = ''; |
| 86 | foreach (<$fh>) { |
| 87 | chompscip-perl cpan RDF-NS 20230619 App/rdfns/chomp().; |
| 88 | next if /^#/; |
| 89 | my @fields = splitscip-perl cpan RDF-NS 20230619 App/rdfns/split(). "\t", $_scip-perl cpan RDF-NS 20230619 App/rdfns/$_.; |
| 90 | if ($fields[2] ne $date) { |
| 91 | sayscip-perl cpan RDF-NS 20230619 App/rdfns/say(). $date=$fields[2]; |
| 92 | } |
| 93 | } |
| 94 | 0; |
| 95 | } |
| 96 | |
| 97 | 1; |
| 98 | __END__ |
| 99 | |
| 100 | =head1 NAME |
| 101 | |
| 102 | App::rdfns - quickly get common URI namespaces |
| 103 | |
| 104 | =head1 SEE ALSO |
| 105 | |
| 106 | This module implements the command line client L<rdfns>. |
| 107 | |
| 108 | =encoding utf8 |
| 109 | |
| 110 | =head1 COPYRIGHT AND LICENSE |
| 111 | |
| 112 | This software is copyright (c) 2013- by Jakob Voß. |
| 113 | |
| 114 | This is free software; you can redistribute it and/or modify it under |
| 115 | the same terms as the Perl 5 programming language system itself. |
| 116 | |
| 117 | =cut |