lib/FAIR/Profile/Class.pm

filter: Statementstmt 100% 45 / 45 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 96.7% 60 / 62 CC 3 SCAR 2.5
CC
3
Cov
96%
_generate_URI
2.0
add_Property
2.0
BEGIN
1.0
CRAP 1.3
« lib/FAIR/Profile/Property.pm ↑ Summary blib/lib/FAIR/Data.pm »
1 package FAIR::Profile::Class;
2 6 $FAIR::Profile::Class::VERSION = '0.41';
3  
4  
5 # ABSTRACT: A FAIR Class is a meta representation of a data resources Class
6  
7 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use FAIR::NAMESPACES;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use vars qw($AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use FAIR::Profile::SerializableProperty;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use base 'FAIR::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # perl 5.18 warns about smartmatch...
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #use vars qw /$VERSION/;
18 #$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/;
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35 6 has URI => (
36 is => 'rw',
37 isa => "Str",
38 builder => '_generate_URI',
39 );
40  
41 has type => (
42 is => 'rw',
43 isa => 'ArrayRef[Str]',
44 traits => [qw/Serializable/], # it is, but it is handled differently than most serializable traits
45 5 ▶ default => sub {[FAIR.'FAIRClass']},
Subroutine __ANON__: called CC=1 SCAR=0.0
46 6 );
47  
48 6 has label => (
49 is => 'rw',
50 isa => "Str",
51 default => 'FAIR Profile Class',
52 traits => [qw/Serializable/],
53 );
54  
55 has hasProperty => (
56 is => 'rw',
57 isa => 'ArrayRef[FAIR::Profile::Property]',
58 traits => [qw/Serializable/],
59 writer => '_add_Property',
60 5 ▶ default => sub {[]},
Subroutine __ANON__: called CC=1 SCAR=0.0
61 6 );
62  
63 6 has provenance => (
64 is => 'rw',
65 isa => 'FAIR::Profile',
66 traits => [qw/Serializable/],
67 );
68  
69 6 has onClassType => ( # represents the OWL Class URI
70 is => 'rw',
71 isa => "Str", # TODO - this should be constrained to be a URI
72 traits => [qw/Serializable/],
73 );
74  
75  
76 sub _generate_URI {
77 1 ▶ my ($self, $newval) = @_;
Subroutine _generate_URI: called CC=2 SCAR=7.0
78 1 ▶ return $newval if $newval;
Branch: 1 branch
BranchTrueFalseTotal
if $newval 0 1 1
79
80 1 my $ug = UUID::Generator::PurePerl->new();
81 1 my $ug1 = $ug->generate_v4()->as_string;
82 1 return "http://datafairport.org/sampledata/profileschemaclass/$ug1";
83 }
84  
85 sub add_Property {
86 6 ▶ my ($self, $p) = @_;
Subroutine add_Property: called CC=2 SCAR=7.0
Pod documented
87 # print STDERR "ADD PROPERTY TYPE:", $p->meta->name, "\n";
88 6 ▶ die "not a FAIR Profile Schema Property " .($p->type)."\n" unless (FAIR.'FAIRProperty' ~~ $p->type);
Branch: 1 branch
BranchTrueFalseTotal
unless &FAIR() . 'FAIRProperty' ~~ $p->type 0 6 6
89 6 my $ps = $self->hasProperty;
90 6 push @$ps, $p;
91 6 $self->_add_Property($ps);
92 6 return 1;
93 }
94  
95  
96 6 1;
97  
98 __END__
99  
100 =pod
101  
102 =encoding UTF-8
103  
104 =head1 NAME
105  
106 FAIR::Profile::Class - A FAIR Class is a meta representation of a data resources Class
107  
108 =head1 VERSION
109  
110 version 0.41
111  
112 =head1 SYNOPSIS
113  
114 use FAIR::Profile::Class;
115 use FAIR::Profile::Property;
116
117 my $ProfileClass = FAIR::Profile::Class->new(
118 class_type => DCAT."dataset", # DCAT is an exported constant
119 URI => "http://example.org//ProfileClasses/ThisClass.rdf",
120 label => "core metadata for the thesis submission"
121 );
122  
123 my $TitleProperty = FAIR::Profile::Property->new(
124 property_type => DCT.'title', # DCT is an exported constant
125 allow_multiple => "false",
126 );
127 $TitleProperty->set_RequirementStatus('required');
128 $TitleProperty->add_ValueRange(XSD."string");
129 $ProfileClass->add_Property($TitleProperty);
130  
131 =head1 DESCRIPTION
132  
133 DCAT Class describes a group of metadata elements that should be
134 associated with a given information entity. They ARE NOT containers for this metadata,
135 they only describe what that metadata should look like (meta-meta-data :-) )
136  
137 Effectively, this module groups-together a set of properties and their value-constraints.
138  
139 =head1 NAME
140  
141 FAIR::Profile::Class - a module representing a FAIR Profile Class
142  
143 =head1 AUTHORS
144  
145 Mark Wilkinson (markw at illuminae dot com)
146  
147 =head1 METHODS
148  
149 =head2 new
150  
151 Title : new
152 Usage : my $Class = FAIR::Profile::Class->new();
153 Function: Builds a new FAIR::Profile::Class
154 Returns : FAIR::Profile::Class
155 Args : label => $string
156 class_type => $URI (possibly an OWL class URI)
157 URI => $URI (optional - a unique URI will be auto-generated)
158  
159 =head2 label
160  
161 Title : label
162 Usage : $label = $Class->label($label);
163 Function: get/set the RDF label for this object when serialized
164 Returns : string
165 Args : string
166  
167 =head2 onClassType
168  
169 Title : onClassType
170 Usage : $class_type = $Class->onClassType($class_type);
171 Function: get/set the class type (should be a URI, e.g. of an ontology class)
172 Returns : string
173 Args : string
174  
175 =head2 URI
176  
177 Title : URI
178 Usage : $uri = $Class->URI($uri);
179 Function: get/set the URI for this Class - the URI in the RDF
180 Returns : string (should be a URI)
181 Args : string (should be a URI)
182 notes: if this is not supplied, a unique URI will be automatically generated
183  
184 =head2 add_Property
185  
186 Title : add_Property
187 Usage : $Class->add_Property($Property);
188 Function: add a new FAIR::Profile::Property to the Profile Class
189 Returns : boolean (1 for success)
190 Args : FAIR::Profile::Property
191  
192 =head2 hasProperty
193  
194 Title : hasProperty
195 Usage : $Class->hasProperty();
196 Function: Retrieve all properties of the Class
197 Returns : listref of FAIR::Profile::Property objects
198 Args : none
199  
200 =head1 AUTHOR
201  
202 Mark Denis Wilkinson (markw [at] illuminae [dot] com)
203  
204 =head1 COPYRIGHT AND LICENSE
205  
206 This software is Copyright (c) 2016 by Mark Denis Wilkinson.
207  
208 This is free software, licensed under:
209  
210 The Apache License, Version 2.0, January 2004
211  
212 =cut
« lib/FAIR/Profile/Property.pm ↑ Summary blib/lib/FAIR/Data.pm »