Web-ID
view release on metacpan or search on metacpan
lib/Web/ID/Util.pm view on Meta::CPAN
package Web::ID::Util;
use 5.010;
use strict;
use utf8;
BEGIN {
$Web::ID::Util::AUTHORITY = 'cpan:TOBYINK';
$Web::ID::Util::VERSION = '1.927';
}
use match::simple qw/match/;
use Carp qw/confess/;
use Math::BigInt 0 try => 'GMP';
use RDF::Trine::NamespaceMap;
use List::MoreUtils qw(:all !true !false);
use Exporter::Tiny;
our @EXPORT = qw(
make_bigint_from_node get_trine_model u uu
true false read_only read_write
);
our @EXPORT_OK = (
@EXPORT,
grep {!/^(true|false)$/} @List::MoreUtils::EXPORT_OK
);
our @ISA = qw( Exporter::Tiny );
use constant {
read_only => 'ro',
read_write => 'rw',
};
use constant {
true => !!1,
false => !!0,
};
sub u (;$)
{
state $namespaces //= RDF::Trine::NamespaceMap->new({
rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
rdfs => 'http://www.w3.org/2000/01/rdf-schema#',
owl => 'http://www.w3.org/2002/07/owl#',
xsd => 'http://www.w3.org/2001/XMLSchema#',
foaf => 'http://xmlns.com/foaf/0.1/',
cert => 'http://www.w3.org/ns/auth/cert#',
rsa => 'http://www.w3.org/ns/auth/rsa#',
});
if (@_)
{
my $rv = $namespaces->uri(@_)
or confess "couldn't expand term $_[0]";
return $rv;
}
return $namespaces;
}
sub uu ($)
{
return u(shift)->uri;
}
sub get_trine_model
{
my ($uri, $model) = @_;
$model //= "RDF::Trine::Model"->new;
eval {
"RDF::Trine::Parser"->parse_url_into_model($uri, $model);
};
return $model;
}
sub make_bigint_from_node
{
my ($node, %opts) = @_;
state $test_hex = [
uu('cert:hex'),
uu('xsd:hexBinary'),
];
state $test_unsigned = [
uu('cert:decimal'),
uu('cert:int'),
uu('xsd:unsignedLong'),
uu('xsd:unsignedInt'),
uu('xsd:unsignedShort'),
uu('xsd:unsignedByte'),
uu('xsd:positiveInteger'),
uu('xsd:nonNegitiveInteger'),
];
state $test_signed = [
uu('xsd:integer'),
( run in 0.905 second using v1.01-cache-2.11-cpan-524268b4103 )