| 1 | #----------------------------------------------------------------- | ||||||||||||||
| 2 | # OWL::Data::Object | ||||||||||||||
| 3 | # Author: Edward Kawas <edward.kawas@gmail.com>, | ||||||||||||||
| 4 | # Martin Senger <martin.senger@gmail.com> | ||||||||||||||
| 5 | # For copyright and disclaimer see below. | ||||||||||||||
| 6 | # | ||||||||||||||
| 7 | # $Id: Object.pm,v 1.2 2010-01-07 21:46:39 ubuntu Exp $ | ||||||||||||||
| 8 | #----------------------------------------------------------------- | ||||||||||||||
| 9 | |||||||||||||||
| 10 | package OWL::Data::Object; | ||||||||||||||
| 11 | 3 | ▶ | use base ("OWL::Base"); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | # add versioning to this module | ||||||||||||||
| 15 | 3 | ▶ | use vars qw /$VERSION/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 3 | $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /: (\d+)\.(\d+)/; | |||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 NAME | ||||||||||||||
| 19 | |||||||||||||||
| 20 | OWL::Data::Object | ||||||||||||||
| 21 | |||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||
| 23 | |||||||||||||||
| 24 | use OWL::Data::Object; | ||||||||||||||
| 25 | |||||||||||||||
| 26 | # create an object with a namespace of NCBI_gi and id 545454 | ||||||||||||||
| 27 | my $data = OWL::Data::Object->new (namespace=>"NCBI_gi", id=>"545454"); | ||||||||||||||
| 28 | |||||||||||||||
| 29 | # set/get an article name for this data object | ||||||||||||||
| 30 | $data->name ('myObject'); | ||||||||||||||
| 31 | print $data->name; | ||||||||||||||
| 32 | |||||||||||||||
| 33 | # set/get an id for this data object | ||||||||||||||
| 34 | $data->id ('myID'); | ||||||||||||||
| 35 | print $data->id; | ||||||||||||||
| 36 | |||||||||||||||
| 37 | # check if this data object is a primitive type | ||||||||||||||
| 38 | print "a primitive" if $data->primitive; | ||||||||||||||
| 39 | print "not a primitive" if not $data->primitive; | ||||||||||||||
| 40 | |||||||||||||||
| 41 | # get a formatted string representation of this data object | ||||||||||||||
| 42 | print $data->toString; | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =head1 DESCRIPTION | ||||||||||||||
| 45 | |||||||||||||||
| 46 | An object representing an owl object (usually consisting of a namespace and id) | ||||||||||||||
| 47 | |||||||||||||||
| 48 | =head1 AUTHORS | ||||||||||||||
| 49 | |||||||||||||||
| 50 | Edward Kawas (edward.kawas [at] gmail [dot] com) | ||||||||||||||
| 51 | Martin Senger (martin.senger [at] gmail [dot] com) | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =cut | ||||||||||||||
| 54 | |||||||||||||||
| 55 | #----------------------------------------------------------------- | ||||||||||||||
| 56 | # A list of allowed attribute names. See OWL::Base for details. | ||||||||||||||
| 57 | #----------------------------------------------------------------- | ||||||||||||||
| 58 | |||||||||||||||
| 59 | =head1 ACCESSIBLE ATTRIBUTES | ||||||||||||||
| 60 | |||||||||||||||
| 61 | Details are in L<OWL::Base>. Here just a list of them: | ||||||||||||||
| 62 | |||||||||||||||
| 63 | =over | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =item B<namespace> | ||||||||||||||
| 66 | |||||||||||||||
| 67 | =item B<id> | ||||||||||||||
| 68 | |||||||||||||||
| 69 | =item B<name> | ||||||||||||||
| 70 | |||||||||||||||
| 71 | An article name for this datatype. Note that the article name depends | ||||||||||||||
| 72 | on the context where this object is used. | ||||||||||||||
| 73 | |||||||||||||||
| 74 | |||||||||||||||
| 75 | =item B<primitive> | ||||||||||||||
| 76 | |||||||||||||||
| 77 | A boolean property indicating if this data type is a primitive owl | ||||||||||||||
| 78 | type or not. | ||||||||||||||
| 79 | |||||||||||||||
| 80 | =back | ||||||||||||||
| 81 | |||||||||||||||
| 82 | =cut | ||||||||||||||
| 83 | |||||||||||||||
| 84 | { | ||||||||||||||
| 85 | 3 | my %_allowed = | |||||||||||||
| 86 | ( | ||||||||||||||
| 87 | id => undef, | ||||||||||||||
| 88 | namespace => undef, | ||||||||||||||
| 89 | primitive => {type => OWL::Base->BOOLEAN}, | ||||||||||||||
| 90 | ); | ||||||||||||||
| 91 | |||||||||||||||
| 92 | 3 | ▶ | sub _accessible { | ||||||||||||
|
Subroutine
_accessible: called CC=2 SCAR=7.2
| |||||||||||||||
| 93 | 3 | my ($self, $attr) = @_; | |||||||||||||
| 94 | 3 | ▶ | exists $_allowed{$attr} or $self->SUPER::_accessible ($attr); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 95 | } | ||||||||||||||
| 96 | 12 | ▶ | sub _attr_prop { | ||||||||||||
|
Subroutine
_attr_prop: called CC=3 SCAR=11.0
| |||||||||||||||
| 97 | 12 | my ($self, $attr_name, $prop_name) = @_; | |||||||||||||
| 98 | 12 | my $attr = $_allowed {$attr_name}; | |||||||||||||
| 99 | 12 | ▶ | return ref ($attr) ? $attr->{$prop_name} : $attr if $attr; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 100 | 8 | return $self->SUPER::_attr_prop ($attr_name, $prop_name); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | } | ||||||||||||||
| 103 | |||||||||||||||
| 104 | #----------------------------------------------------------------- | ||||||||||||||
| 105 | |||||||||||||||
| 106 | =head1 SUBROUTINES | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =cut | ||||||||||||||
| 109 | |||||||||||||||
| 110 | #----------------------------------------------------------------- | ||||||||||||||
| 111 | # init | ||||||||||||||
| 112 | #----------------------------------------------------------------- | ||||||||||||||
| 113 | 3 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 114 | 8 | my ($self) = shift; | |||||||||||||
| 115 | 8 | $self->SUPER::init(); | |||||||||||||
| 116 | 8 | $self->id (''); | |||||||||||||
| 117 | 8 | $self->namespace (''); | |||||||||||||
| 118 | 8 | $self->primitive ('no'); | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | |||||||||||||||
| 122 | # return the same value as given (but others may override it - eg, | ||||||||||||||
| 123 | # Boolean changes here 1 to 'true' | ||||||||||||||
| 124 | |||||||||||||||
| 125 | 0 | ▶ | sub _express_value { | ||||||||||||
|
Subroutine
_express_value: not called CC=1 SCAR=6.9
| |||||||||||||||
| 126 | 0 | shift; | |||||||||||||
| 127 | 0 | shift; | |||||||||||||
| 128 | } | ||||||||||||||
| 129 | |||||||||||||||
| 130 | |||||||||||||||
| 131 | 3 | 1; | |||||||||||||
| 132 | __END__ | ||||||||||||||