App/rdfns.pm

filter: Statementstmt 71.9% 41 / 57 Branchbran 64.2% 18 / 28 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 5 totaltotal 63.4% 66 / 104 CC 19 SCAR 26.3
CC
19
Cov
68%
dates
20.0
run
17.8
usage
2.0
CRAP 13.9
« RDF/NS.pm ↑ Summary RDF/SN.pm »
1 package App::rdfns;
2 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use RDF::NS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '20230619';
9  
10 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 8 bless {}, shift;
12 }
13  
14 8 ▶sub run {
Subroutine run: called CC=16 SCAR=28.8
Pod undocumented
15 8 my ($self, @ARGV) = @_;
16 8 my $format = '';
17  
18 8 ▶ return $self->usage if !@ARGV or $ARGV[0] =~ /^(-[?h]|--help)$/;
Branch: 1 branch
BranchTrueFalseTotal
if not @ARGV or $ARGV[0] =~ /^(-[?h]|--help)$/ 0 8 8
Condition33%1/3
not @ARGV or $ARGV[0] =~ /^(-[?h]|--help)$/
l!l&&r!l&&!r
008
MC/DC0%0/2
not @ARGV or $ARGV[0] =~ /^(-[?h]|--help)$/
not @ARGV $ARGV[0] =~ /^(-[?h]|--help)$/
Truth table33%1/3
not(A) or B
A= not @ARGVB= $ARGV[0] =~ /^(-[?h]|--help)$/
ABresult
1X1
011
000
19 8 ▶ return $self->version if $ARGV[0] =~ /^(-v|--version)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[0] =~ /^(-v|--version)$/ 0 8 8
20 8 ▶ return $self->dates if $ARGV[0] eq '--dates';
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[0] eq "--dates" 0 8 8
21  
22 8 my $ns = RDF::NS->new;
23 8 my $sn = $ns->REVERSE;
24  
25 8 foreach my $a (@ARGV) {
26 11 ▶ if ( $a =~ /^([0-9]{8})$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a =~ /^([0-9]{8})$/) 2 9 11
27 2 $ns = RDF::NS->new($a);
28 2 $sn = $ns->REVERSE;
29 2 next;
30 }
31 9 ▶ if ( $a =~ qr{^https?://} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($a =~ qr"^https?://") { } 4 5 9
elsif ($a =~ /:/) { } 0 5 5
elsif ($a =~ s/\.([^.]+)$//) { } 2 3 5
32 4 my $qname = $sn->qname($a);
33 4 ▶ if ($qname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qname) 2 2 4
34 2 $qname =~ s/:$//;
35 2 say $qname;
36 }
37 } elsif ( $a =~ /:/ ) {
38 0 print map { $ns->URI($_)."\n" } split(/[|, ]+/, $a);
39 } elsif ( $a =~ s/\.([^.]+)$// ) {
40 2 my $f = $1;
41 2 ▶ if ( $f eq 'prefix' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f eq 'prefix') { } 1 1 2
elsif ($f =~ /$RDF::NS::FORMATS/) { } 1 0 1
42 1 ▶ print map { "$_\n" if defined $_ } map {
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 1 0 1
43 1 $sn->{$_}
44 } $ns->FORMAT( $format, $a );
45 1 next;
46 } elsif ( $f =~ $RDF::NS::FORMATS ) {
47 1 $format = $f;
48 } else {
49 0 print STDERR "Unknown format: $f\n";
50 }
51 }
52 8 ▶ if ( lc($format) eq 'json' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $format eq 'json') { } 1 7 8
53 1 say join ",\n", $ns->FORMAT( $format, $a );
54 } else {
55 7 say $_ for $ns->FORMAT( $format, $a );
56 }
57 }
58 }
59  
60 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
Pod undocumented
61 0 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 0;
76 }
77  
78 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
79 0 print $RDF::NS::VERSION . "\n";
80 0 0;
81 }
82  
83 0 ▶sub dates {
Subroutine dates: not called CC=4 SCAR=30.0
Pod undocumented
84 0 my $fh = RDF::NS->new->DATA;
85 0 my $date = '';
86 0 foreach (<$fh>) {
87 0 chomp;
88 0 ▶ next if /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^#/ 0 0 0
89 0 my @fields = split "\t", $_;
90 0 ▶ if ($fields[2] ne $date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields[2] ne $date) 0 0 0
91 0 say $date=$fields[2];
92 }
93 }
94 0 0;
95 }
96  
97 1 1;
98 __END__
« RDF/NS.pm ↑ Summary RDF/SN.pm »