| 1 | package RDF::NS; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | our $VERSION = '20230619'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use File::ShareDir; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use RDF::SN; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | our $FORMATS = qr/ttl|n(otation)?3|sparql|xmlns|txt|beacon|json/; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | our $DATE_REGEXP = qr/^([0-9]{4})-?([0-9][0-9])-?([0-9][0-9])$/; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 28 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=19 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 28 | ▶ | my $class = ref( $_[0] ) ? ref(shift) : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 28 | ▶ | my $from = @_ % 2 ? shift : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 28 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 28 | ▶ | my $at = $options{at} || 'any'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{'at'} || 'any'
MC/DC100%1/1
$options{'at'} || 'any'
$options{'at'}
Truth table100%2/2
A
A= $options{'at'}
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 28 | my $warn = $options{'warn'}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 28 | ▶ | $from = $options{from} if exists $options{from}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 28 | ▶ | $from = 'any' if !$from or $from eq 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $from or $from eq 1
MC/DC50%1/2
not $from or $from eq 1
not $from
$from eq 1
Truth table66%2/3
not(A) or B
A= not $fromB= $from eq 1
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 28 | ▶ | if ( ( ref($from) || '' ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $from || ''
MC/DC100%1/1
ref $from || ''
ref $from
Truth table100%2/2
A
A= ref $from
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my $self = bless $from, $class; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | foreach my $prefix ( keys %$self ) { | |||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | unless ( $self->SET( $prefix => $self->{$prefix}, $warn ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | delete $self->{$prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 27 | ▶ | if ( $from =~ $DATE_REGEXP ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 16 | $at = "$1$2$3"; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 16 | $from = 'any'; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | elsif ( $at =~ $DATE_REGEXP ) { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $at = "$1$2$3"; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | elsif ( $at !~ 'any' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | croak "RDF::NS expects 'any', '1' or a date as YYYY-MM-DD"; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 27 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 27 | my $fh = $self->DATA($from); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 27 | foreach (<$fh>) { | |||||||||||||||||||||||||||||||||||||||||
| 51 | 46930 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 46930 | ▶ | next if /^#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 46930 | my ( $prefix, $namespace, $date ) = split "\t", $_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 46930 | ▶ | last if $date and $at ne 'any' and $date > $at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$date and $at ne "any" and $date > $at
$date and $at ne "any"
MC/DC66%2/3
$date and $at ne "any" and $date > $at
$date
$at ne "any"
$date > $at
Truth table75%3/4
A and B and C
A= $dateB= $at ne "any"C= $date > $at
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 46913 | $self->SET( $prefix => $namespace, $warn ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 27 | close($fh); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 27 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 27 | ▶ | sub DATA { # TODO: document | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DATA: called CC=5 SCAR=17.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 27 | my ( $self, $from ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | ▶ | $from = File::ShareDir::dist_file( 'RDF-NS', "prefix.cc" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$from // "any"
MC/DC0%0/1
$from // "any"
$from
Truth table50%1/2
A
A= $from
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | if ( $from // 'any' ) eq 'any'; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 27 | ▶ | croak "prefix file or date not found: $from" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | unless -f $from; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 27 | ▶ | open( my $fh, '<', $from ) or croak "failed to open $from"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 27 | $fh; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 46915 | ▶ | sub SET { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SET: called CC=7 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 46915 | my ( $self, $prefix, $namespace, $warn ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 46915 | ▶ | if ( $prefix =~ /^(isa|can|new|uri)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | carp "Cannot support prefix '$prefix'" if $warn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ( $prefix =~ /^[a-z][a-z0-9]*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 46914 | ▶ | if ( $namespace =~ /^[a-z][a-z0-9]*:[^"<>]*$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 46914 | $self->{$prefix} = $namespace; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 46914 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | elsif ($warn) { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | carp "Skipping invalid $prefix namespace $namespace"; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif ($warn) { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | carp "Skipping unusual prefix '$prefix'"; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | *LOAD = *new; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | ▶ | sub COUNT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
COUNT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | scalar keys %{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 13 | ▶ | sub FORMAT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FORMAT: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | ▶ | my $format = shift || ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 13 | ▶ | $format = 'TTL' if $format =~ /^n(otation)?3$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 13 | ▶ | if ( lc($format) =~ $FORMATS ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $format = uc($format); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $self->$format(@_); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | elsif ( $format eq "" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | ▶ | $self->MAP( sub { $self->{$_} }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | sub PREFIX { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PREFIX: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | my ( $self, $uri ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | foreach my $prefix ( sort keys %$self ) { | |||||||||||||||||||||||||||||||||||||||||
| 117 | 1308 | ▶ | return $prefix if $uri eq $self->{$prefix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | sub PREFIXES { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PREFIXES: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my ( $self, $uri ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | my @prefixes; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | while ( my ( $prefix, $namespace ) = each %$self ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 698 | ▶ | push @prefixes, $prefix if $uri eq $namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | return ( sort(@prefixes) ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 21 | ▶ | sub REVERSE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
REVERSE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 21 | RDF::SN->new( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | ▶ | sub TTL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TTL: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | ▶ | $self->MAP( sub { "\@prefix $_: <" . $self->{$_} . "> ." }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | ▶ | sub SPARQL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SPARQL: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | $self->MAP( sub { "PREFIX $_: <" . $self->{$_} . ">" }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | sub XMLNS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
XMLNS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | ▶ | $self->MAP( sub { "xmlns:$_=\"" . $self->{$_} . "\"" }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | ▶ | sub TXT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TXT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | $self->MAP( sub { "$_\t" . $self->{$_} }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | sub JSON { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
JSON: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | $self->MAP( sub { "\"$_\": \"" . $self->{$_} . "\"" }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | ▶ | sub BEACON { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEACON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | $self->MAP( sub { "#PREFIX: " . $self->{$_} }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | sub SELECT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SELECT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | $self->MAP( sub { $_ => $self->{$_} }, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # functional programming rulez! | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 39 | ▶ | sub MAP { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
MAP: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 39 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 174 | my @ns = | ||||||||||||||||||||||||||||||||||||||||||
| 175 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 39 | ▶ | ? ( grep { $self->{$_} } map { split /[|, ]+/ } @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | : keys %$self; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 39 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 34 | return map { $code->() } sort @ns; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | local $_ = $ns[0]; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 5 | return $code->(); | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 21 | ▶ | sub GET { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GET: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 21 | $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | ▶ | sub BLANK { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BLANK: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 6 | *URI = *uri; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | ▶ | sub uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 8 | ▶ | return $1 if $_[0] =~ /^<([a-zA-Z][a-zA-Z+.-]*:.+)>$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | ▶ | return $self->BLANK( $_[0] ) if $_[0] =~ /^_(:.*)?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | return unless shift =~ /^([a-z][a-z0-9]*)?([:_]([^:]+))?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | ▶ | my $ns = $self->{ defined $1 ? $1 : '' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | ▶ | return unless defined $ns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | ▶ | return $self->GET($ns) unless $3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | return $self->GET( $ns . $3 ); | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 52 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 52 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 52 | ▶ | return unless $AUTOLOAD =~ /^.*::([a-z][a-z0-9]*)?(_([^:]+)?)?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 23 | ▶ | return $self->BLANK( defined $3 ? "_:$3" : '_' ) unless $1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 21 | ▶ | my $ns = $self->{$1} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 21 | ▶ | my $local = defined $3 ? $3 : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 21 | ▶ | return $self->GET($ns) unless defined $local; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 9 | return $self->GET( $ns . $local ); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub UPDATE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
UPDATE: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my ( $self, $file, $date ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | croak "RDF::NS expects a date as YYYY-MM-DD" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$date and $date =~ /$RDF::NS::DATE_REGEXP/
MC/DC0%0/2
$date and $date =~ /$RDF::NS::DATE_REGEXP/
$date
$date =~ /$RDF::NS::DATE_REGEXP/
Truth table0%0/3
A and B
A= $dateB= $date =~ /$RDF::NS::DATE_REGEXP/
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | unless $date and $date =~ $DATE_REGEXP; | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $date = "$1$2$3"; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $old = RDF::NS->new($file); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my ( @create, @update, @delete ); | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | open( my $fh, '>>', $file ) or croak "failed to open $file"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | while ( my ( $prefix, $namespace ) = each %$self ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ( !exists $old->{$prefix} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | push @create, $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | elsif ( $old->{$prefix} ne $namespace ) { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | push @update, $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | push @lines, "$prefix\t$namespace"; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | while ( my ( $prefix, $namespace ) = each %$old ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ( !exists $self->{$prefix} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | push @delete, $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | print $fh "$_\t$date\n" for sort @lines; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | create => [ sort @create ], | |||||||||||||||||||||||||||||||||||||||||
| 253 | update => [ sort @update ], | ||||||||||||||||||||||||||||||||||||||||||
| 254 | delete => [ sort @delete ], | ||||||||||||||||||||||||||||||||||||||||||
| 255 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 259 | __END__ | ||||||||||||||||||||||||||||||||||||||||||