lib/OWL/Data/Def/OWLClass.pm

filter: Statementstmt 100% 38 / 38 Branchbran 68.7% 11 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 92.0% 58 / 63 CC 9 SCAR 9.9
CC
9
Cov
91%
__ANON__
4.2
_attr_prop
3.0
__ANON__
3.0
CRAP 2.7
« lib/OWL/Data/Boolean.pm ↑ Summary lib/OWL/Data/DateTime.pm »
1 #-----------------------------------------------------------------
2 # OWL::Data::Def::OWLClass
3 # Author: Edward Kawas <edward.kawas@gmail.com>,
4 # For copyright and disclaimer see below.
5 #
6 # $Id: OWLClass.pm,v 1.22 2010-01-07 21:48:08 ubuntu Exp $
7 #-----------------------------------------------------------------
8 package OWL::Data::Def::OWLClass;
9 2 ▶use base qw( OWL::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 # add versioning to this module
13 2 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 $VERSION = sprintf "%d.%02d", q$Revision: 1.24 $ =~ /: (\d+)\.(\d+)/;
15
16 =head1 NAME
17
18 OWL::Data::Def::OWLClass - definition of an owl class
19
20 =head1 SYNOPSIS
21
22 use OWL::Data::Def::OWLClass;
23
24 # create a new data type
25 my $class = new OWL::Data::Def::OWLClass
26 ( name => 'MySequenceClass',
27 type => 'http://some.domain.com/classes#MySequenceClass',
28 parent => 'http://some.domain.com/classes#MySequenceClassParent',
29 );
30
31 # get the name of this owl class
32 print $class->name;
33
34
35 =cut
36
37 =head1 DESCRIPTION
38
39 A container representing an OWL class definition
40
41 =head1 AUTHORS
42
43 Edward Kawas (edward.kawas [at] gmail [dot] com)
44
45 =cut
46
47 #-----------------------------------------------------------------
48 # A list of allowed attribute names. See OWL::Base for details.
49 #-----------------------------------------------------------------
50
51 =head1 ACCESSIBLE ATTRIBUTES
52
53 Details are in L<OWL::Base>. Here just a list of them:
54
55 =over
56
57 =item B<name>
58
59 A name of this owl class
60
61 =item B<parent>
62
63 A parent for this owl class ... defaults to OWL::Data::OWL::Class
64
65 =item B<type>
66
67 The type of this owl class
68
69 =back
70
71 =cut
72
73 {
74 my %_allowed = (
75 name => {
76 # name set when you set the type!
77 type => OWL::Base->STRING,
78 },
79 parent => {
80 type => OWL::Base->STRING,
81 30 ▶ post => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
82 30 my ($self) = shift;
83 30 my $name = @{$self->parent}[-1];
84 30 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 30 30
85 # $name = 'OWL::Data::OWL::Class' unless defined $name;
86 30 ▶ if ($name eq 'OWL::Data::OWL::Class') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'OWL::Data::OWL::Class') { } 20 10 30
87 # add to parents array
88 20 $self->add_module_parent($name);
89 } else {
90 # add to parents array
91 10 $self->add_module_parent($self->owlClass2module( $self->uri2package($name) ));
92 }
93 },
94 is_array => 1,
95 },
96 type => {
97 type => OWL::Base->STRING,
98 20 ▶ post => sub {
Subroutine __ANON__: called CC=4 SCAR=14.3
99 20 my ($self) = shift;
100 20 my $package = $self->uri2package($self->type);
101 20 $self->{module_name} = $self->owlClass2module($package);
102 # extract our name and set it
103 20 ▶ my $name = $1 if $package =~ m|\:\:(\w+)$|gi;
Branch: 1 branch
BranchTrueFalseTotal
if $package =~ /\:\:(\w+)$/gi 20 0 20
104 20 ▶ $name = $package unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 20 20
105 20 $self->name($name);
106 # bnodes are typed differently than URI nodes
107 20 ▶ $self->{type} = "" if $package =~ m/^genid/ig;
Branch: 1 branch
BranchTrueFalseTotal
if $package =~ /^genid/gi 0 20 20
108 }
109 },
110 # HashOfHash: property_name => {keys: object, range, name, module}
111 2 has_value_property => {type => 'HASH', is_array => 1 },
112 object_properties =>
113 { type => 'OWL::Data::Def::ObjectProperty', is_array => 1 },
114 datatype_properties =>
115 { type => 'OWL::Data::Def::DatatypeProperty', is_array => 1 },
116
117 # used internally (but cannot start with underscore - Template would ignore them)
118 # the full package name for this class
119 module_name => undef,
120 # the full package names for parents
121 module_parent => { type => OWL::Base->STRING, is_array => 1 },
122 # HashOfHash: property_name => {keys: name, max, min}
123 cardinality_constraints => {type => 'HASH', is_array => 0 },
124 # hash: key: onProperty, value: hash of restrictionURI strings as module names as keys with the value of 1
125 values_from_property => {type => 'HASH' },
126 );
127
128 40 ▶ sub _accessible {
Subroutine _accessible: called CC=2 SCAR=6.9
129 40 my ( $self, $attr ) = @_;
130 40 ▶ exists $_allowed{$attr} or $self->SUPER::_accessible($attr);
Branch: 1 branch
BranchTrueFalseTotal
exists $_allowed{$attr} or $self->SUPER::_accessible($attr) 30 10 40
131 }
132
133 110 ▶ sub _attr_prop {
Subroutine _attr_prop: called CC=3 SCAR=11.0
134 110 my ( $self, $attr_name, $prop_name ) = @_;
135 110 my $attr = $_allowed{$attr_name};
136 110 ▶ return ref($attr) ? $attr->{$prop_name} : $attr if $attr;
Branch: 2 branches
BranchTrueFalseTotal
if $attr 102 8 110
ref $attr ? : 102 0 102
137 8 return $self->SUPER::_attr_prop( $attr_name, $prop_name );
138 }
139 }
140
141 #-----------------------------------------------------------------
142
143 =head1 SUBROUTINES
144
145 =cut
146
147 #-----------------------------------------------------------------
148 # init
149 #-----------------------------------------------------------------
150 2 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
151 20 my ($self) = shift;
152 20 $self->SUPER::init();
153 20 $self->add_parent('OWL::Data::OWL::Class');
154 # initialize empty hash for cardinality_constraints
155 20 $self->cardinality_constraints(\());
156 20 $self->values_from_property(\());
157 }
158 2 1;
159 __END__
« lib/OWL/Data/Boolean.pm ↑ Summary lib/OWL/Data/DateTime.pm »