| 1 | package Types::Attean; | ||
| 2 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 2 | ▶ | use Type::Library -base, -declare => qw( |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | AtteanIRI | ||
| 7 | AtteanBlank | ||
| 8 | AtteanLiteral | ||
| 9 | AtteanSubject AtteanPredicate AtteanObject | ||
| 10 | AtteanGraph | ||
| 11 | AtteanTriple | ||
| 12 | AtteanQuad | ||
| 13 | 2 | ); | |
| 14 | 2 | ▶ | use Types::Standard qw( Str InstanceOf ConsumerOf ScalarRef ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 2 | ▶ | use Types::URI qw( Uri Iri ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 2 | ▶ | use Types::Namespace qw( Namespace ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 2 | ▶ | use Types::Path::Tiny qw( Path ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | use Types::UUID qw( Uuid ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 2 | my $TrineNode = InstanceOf['RDF::Trine::Node::Resource']; | |
| 21 | 2 | my $TrineNS = InstanceOf['RDF::Trine::Namespace']; | |
| 22 | 2 | my $XmlNS = InstanceOf['XML::Namespace']; | |
| 23 | |||
| 24 | |||
| 25 | 2 | our $VERSION = '0.040'; | |
| 26 | |||
| 27 | =head1 NAME | ||
| 28 | |||
| 29 | Types::Attean - Type constraints for dealing with Attean classes | ||
| 30 | |||
| 31 | =head1 SYNOPSIS | ||
| 32 | |||
| 33 | TODO | ||
| 34 | |||
| 35 | package IRI::Counter { | ||
| 36 | use Moo; # or Moose | ||
| 37 | use Types::Attean qw( AtteanIRI ); | ||
| 38 | |||
| 39 | has iri => ( | ||
| 40 | is => "ro", | ||
| 41 | isa => AtteanIRI, | ||
| 42 | required => 1, | ||
| 43 | ); | ||
| 44 | |||
| 45 | sub count_uses_in_document { ... } | ||
| 46 | } | ||
| 47 | |||
| 48 | =head1 DESCRIPTION | ||
| 49 | |||
| 50 | Types::Attean is a type constraint library suitable for use with | ||
| 51 | L<Moo>/L<Moose> attributes, L<Kavorka> sub signatures, and so | ||
| 52 | forth. It builds on L<Types::URI>. | ||
| 53 | |||
| 54 | =head1 TYPES | ||
| 55 | |||
| 56 | =over | ||
| 57 | |||
| 58 | =item C<< AtteanIRI >> | ||
| 59 | |||
| 60 | A class type for L<Attean::IRI>. | ||
| 61 | |||
| 62 | Can coerce from L<URI>, L<IRI>, L<URI::Namespace>, | ||
| 63 | L<RDF::Trine::Node::Resource>, L<RDF::Trine::Namespace>, | ||
| 64 | L<XML::Namespace> and strings. | ||
| 65 | |||
| 66 | Additionally, a C<ScalarRef> can be coerced into a C<data> URI. | ||
| 67 | |||
| 68 | =item C<< AtteanBlank >> | ||
| 69 | |||
| 70 | A role type for L<Attean::API::Blank>. | ||
| 71 | |||
| 72 | =item C<< AtteanLiteral >> | ||
| 73 | |||
| 74 | A role type for L<Attean::API::Literal>. | ||
| 75 | |||
| 76 | =item C<< AtteanSubject >> | ||
| 77 | |||
| 78 | A role type for a term that can be used as a subject | ||
| 79 | in a triple or quad | ||
| 80 | (i.e., L<Attean::API::BlankOrIRI>). | ||
| 81 | |||
| 82 | =item C<< AtteanPredicate >> | ||
| 83 | |||
| 84 | A role type for a term that can be used as a predicate | ||
| 85 | in a triple or quad | ||
| 86 | (i.e., L<Attean::API::IRI>). | ||
| 87 | |||
| 88 | =item C<< AtteanObject >> | ||
| 89 | |||
| 90 | A role type for a term that can be used as an object | ||
| 91 | in a triple or quad | ||
| 92 | (i.e., L<Attean::API::Term>). | ||
| 93 | |||
| 94 | =item C<< AtteanGraph >> | ||
| 95 | |||
| 96 | A role type for a term that can be used as a graph | ||
| 97 | in a quad | ||
| 98 | (i.e., L<Attean::API::BlankOrIRI>). | ||
| 99 | |||
| 100 | =item C<< AtteanTriple >> | ||
| 101 | |||
| 102 | A role type for L<Attean::API::Triple>. | ||
| 103 | |||
| 104 | =item C<< AtteanQuad >> | ||
| 105 | |||
| 106 | A role type for L<Attean::API::Quad>. | ||
| 107 | |||
| 108 | =back | ||
| 109 | |||
| 110 | =head1 OTHER COERCIONS | ||
| 111 | |||
| 112 | This library can also coerce from C<Attean::IRI> to the C<Namespace> type defined in L<URI::Namespace>. | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | 2 | __PACKAGE__->add_type( | |
| 117 | name => AtteanIRI, | ||
| 118 | parent => InstanceOf['Attean::IRI'] | ||
| 119 | ); | ||
| 120 | |||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | 2 | AtteanIRI->coercion->add_type_coercions( | |
| 125 | Str ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_) } }, | ||
| 126 | # HashRef ,=> q{ do { require Attean::IRI; "Attean::IRI"->new(URI::FromHash::uri(%$_)) } }, # TODO: Perhaps use for a shortcut to populate rather than parse? | ||
| 127 | Namespace ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->as_string) } }, | ||
| 128 | Uri ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->as_string) } }, | ||
| 129 | Iri ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->as_string) } }, | ||
| 130 | Uuid ,=> q{ do { require Attean::IRI; "Attean::IRI"->new("urn:uuid:$_") } }, | ||
| 131 | Path ,=> q{ do { require Attean::IRI; my $u = "URI::file"->new($_); "Attean::IRI"->new($u->as_string) } }, | ||
| 132 | ScalarRef ,=> q{ do { require Attean::IRI; my $u = "URI"->new("data:"); $u->data($$_); "Attean::IRI"->new($u->as_string) } }, | ||
| 133 | $TrineNode ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->uri_value) } }, | ||
| 134 | $TrineNS ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->uri->uri_value) } }, | ||
| 135 | $XmlNS ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->uri) } }, | ||
| 136 | ); | ||
| 137 | |||
| 138 | |||
| 139 | 2 | require Attean::IRI; | |
| 140 | |||
| 141 | 2 | __PACKAGE__->add_type( | |
| 142 | name => AtteanBlank, | ||
| 143 | parent => ConsumerOf['Attean::API::Blank'] | ||
| 144 | ); | ||
| 145 | |||
| 146 | 2 | __PACKAGE__->add_type( | |
| 147 | name => AtteanLiteral, | ||
| 148 | parent => ConsumerOf['Attean::API::Literal'] | ||
| 149 | ); | ||
| 150 | |||
| 151 | 2 | __PACKAGE__->add_type( | |
| 152 | name => AtteanSubject, | ||
| 153 | parent => ConsumerOf['Attean::API::BlankOrIRI'] | ||
| 154 | ); | ||
| 155 | |||
| 156 | 2 | __PACKAGE__->add_type( | |
| 157 | name => AtteanPredicate, | ||
| 158 | parent => ConsumerOf['Attean::API::IRI'] | ||
| 159 | ); | ||
| 160 | |||
| 161 | 2 | __PACKAGE__->add_type( | |
| 162 | name => AtteanObject, | ||
| 163 | parent => ConsumerOf['Attean::API::Term'] | ||
| 164 | ); | ||
| 165 | |||
| 166 | 2 | __PACKAGE__->add_type( | |
| 167 | name => AtteanGraph, | ||
| 168 | parent => ConsumerOf['Attean::API::BlankOrIRI'] | ||
| 169 | ); | ||
| 170 | |||
| 171 | 2 | __PACKAGE__->add_type( | |
| 172 | name => AtteanTriple, | ||
| 173 | parent => ConsumerOf['Attean::API::Triple'] | ||
| 174 | ); | ||
| 175 | |||
| 176 | 2 | __PACKAGE__->add_type( | |
| 177 | name => AtteanQuad, | ||
| 178 | parent => ConsumerOf['Attean::API::Quad'] | ||
| 179 | ); | ||
| 180 | |||
| 181 | 2 | 1; | |