File Coverage

blib/lib/Types/Attean.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 32 32 100.0


line stmt bran cond sub pod time code
1             use strict;
2 1     1   2221 use warnings;
  1         2  
  1         26  
3 1     1   4  
  1         2  
  1         32  
4             use Type::Library -base, -declare => qw( AtteanIRI );
5 1     1   5 use Types::Standard qw( Str InstanceOf ScalarRef );
  1         3  
  1         6  
6 1     1   319 use Types::URI qw( Uri Iri );
  1         2  
  1         4  
7 1     1   779 use Types::Namespace qw( Namespace );
  1         2  
  1         8  
8 1     1   349 use Types::Path::Tiny qw( Path );
  1         1  
  1         7  
9 1     1   232 use Types::UUID qw( Uuid );
  1         2  
  1         8  
10 1     1   300  
  1         2  
  1         8  
11             my $TrineNode = InstanceOf['RDF::Trine::Node::Resource'];
12             my $TrineNS = InstanceOf['RDF::Trine::Namespace'];
13             my $XmlNS = InstanceOf['XML::Namespace'];
14              
15              
16             our $VERSION = '0.033';
17              
18             =head1 NAME
19              
20             Types::Attean - Type constraints for dealing with Attean classes
21              
22             =head1 SYNOPSIS
23              
24             TODO
25             package IRI::Counter {
26             use Moo; # or Moose
27             use Types::Attean qw( AtteanIRI );
28              
29             has iri => (
30             is => "ro",
31             isa => AtteanIRI,
32             required => 1,
33             );
34              
35             sub count_uses_in_document { ... }
36             }
37              
38             =head1 DESCRIPTION
39              
40             Types::Attean is a type constraint library suitable for use with
41             L<Moo>/L<Moose> attributes, L<Kavorka> sub signatures, and so
42             forth. It builds on L<Types::URI>.
43              
44             =head1 TYPES
45              
46             =over
47              
48             =item C<< AtteanIri >>
49              
50             A class type for L<Attean::IRI>.
51              
52             Can coerce from L<URI>, L<IRI>, L<URI::Namespace>,
53             L<RDF::Trine::Node::Resource>, L<RDF::Trine::Namespace>,
54             L<XML::Namespace> and strings.
55              
56             Additionally, a C<ScalarRef> can be coerced into a C<data> URI.
57              
58             =back
59              
60             =head1 OTHER COERCIONS
61              
62             This library can also coerce from C<Attean::IRI> to the C<Namespace> type defined in L<URI::Namespace>.
63              
64             =cut
65              
66             __PACKAGE__->add_type(
67             name => AtteanIRI,
68             parent => InstanceOf['Attean::IRI']
69             );
70              
71              
72              
73              
74             AtteanIRI->coercion->add_type_coercions(
75             Str ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_) } },
76             # HashRef ,=> q{ do { require Attean::IRI; "Attean::IRI"->new(URI::FromHash::uri(%$_)) } }, # TODO: Perhaps use for a shortcut to populate rather than parse?
77             Namespace ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->as_string) } },
78             Uri ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->as_string) } },
79             Iri ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->as_string) } },
80             Uuid ,=> q{ do { require Attean::IRI; "Attean::IRI"->new("urn:uuid:$_") } },
81             Path ,=> q{ do { require Attean::IRI; my $u = "URI::file"->new($_); "Attean::IRI"->new($u->as_string) } },
82             ScalarRef ,=> q{ do { require Attean::IRI; my $u = "URI"->new("data:"); $u->data($$_); "Attean::IRI"->new($u->as_string) } },
83             $TrineNode ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->uri_value) } },
84             $TrineNS ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->uri->uri_value) } },
85             $XmlNS ,=> q{ do { require Attean::IRI; "Attean::IRI"->new($_->uri) } },
86             );
87              
88              
89             require Attean::IRI;
90              
91              
92             1;