| 1 | #$Id: OntologyServer.pm,v 1.3 2010/06/24 18:23:16 kawas Exp $ | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | MOBY::Client::OntologyServer - A client interface to the Ontology | ||||||||||||||||||||||||||||||||
| 6 | Server at MOBY Central | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | =cut | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | use MOBY::Client::OntologyServer; | ||||||||||||||||||||||||||||||||
| 13 | my $OS = MOBY::Client::OntologyServer->new(); | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | my ($success, $message, $existingURI) = $OS->objectExists(term => "Object"); | ||||||||||||||||||||||||||||||||
| 16 | my ($success, $message, $existingURI) = $OS->serviceExists(term => "Retrieval"); | ||||||||||||||||||||||||||||||||
| 17 | my ($success, $message, $existingURI) = $OS->namespaceExists(term => "NCBI_gi"); | ||||||||||||||||||||||||||||||||
| 18 | my ($success, $message, $existingURI) = $OS->relationshipExists(term => "ISA"); | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | if ($success){ | ||||||||||||||||||||||||||||||||
| 21 | print "object exists and it has the LSID $existingURI\n"; | ||||||||||||||||||||||||||||||||
| 22 | } else { | ||||||||||||||||||||||||||||||||
| 23 | print "object does not exist; additional message from server: $message\n"; | ||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | This module is used primarily as a way of dealing with the | ||||||||||||||||||||||||||||||||
| 32 | flexibility MOBY allows in the use of "common" names | ||||||||||||||||||||||||||||||||
| 33 | versus LSID's. Calling the ontology server using this | ||||||||||||||||||||||||||||||||
| 34 | module will return the LSID of whatever it is you send it, | ||||||||||||||||||||||||||||||||
| 35 | even if you send the LSID itself. As such, you can now simply | ||||||||||||||||||||||||||||||||
| 36 | filter your terms through the ontologyserver and know that | ||||||||||||||||||||||||||||||||
| 37 | what is returned will be an LSID, and skip the checking step | ||||||||||||||||||||||||||||||||
| 38 | yourself. | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | =head1 PROXY SERVERS | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | If your site uses a proxy server, simply set the environment variable | ||||||||||||||||||||||||||||||||
| 44 | MOBY_PROXY=http://your.proxy.server/address | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | Mark Wilkinson (markw at illuminae.com) | ||||||||||||||||||||||||||||||||
| 52 | Nina Opushneva (opushneva at yahoo.ca) | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | BioMOBY Project: http://www.biomoby.org | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | =head2 new | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | Title : new | ||||||||||||||||||||||||||||||||
| 65 | Usage : my $OS = MOBY::OntologyServer->new(%args) | ||||||||||||||||||||||||||||||||
| 66 | Function : | ||||||||||||||||||||||||||||||||
| 67 | Returns : MOBY::OntologyServer object | ||||||||||||||||||||||||||||||||
| 68 | Args : host => URL to ontolgy_server script (default http://mobycentral.cbr.nrc.ca/cgi-bin/OntologyServer.cgi) | ||||||||||||||||||||||||||||||||
| 69 | proxy => URL to an HTTP proxy server if necessarray (optional) | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | package MOBY::Client::OntologyServer; | ||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 77 | 4 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | use vars qw /$VERSION/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 80 | 4 | $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 4 | my $debug = 0; | |||||||||||||||||||||||||||||||
| 83 | 4 | my $user_agent = "MOBY-OntologyServer-Perl"; | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | #Encapsulated class data | ||||||||||||||||||||||||||||||||
| 88 | #___________________________________________________________ | ||||||||||||||||||||||||||||||||
| 89 | #ATTRIBUTES | ||||||||||||||||||||||||||||||||
| 90 | 4 | my %_attr_data = # DEFAULT ACCESSIBILITY | |||||||||||||||||||||||||||||||
| 91 | ( | ||||||||||||||||||||||||||||||||
| 92 | host => ['' ,'read/write'], | ||||||||||||||||||||||||||||||||
| 93 | proxy => [ undef, 'read/write' ], | ||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | #_____________________________________________________________ | ||||||||||||||||||||||||||||||||
| 97 | # METHODS, to operate on encapsulated class data | ||||||||||||||||||||||||||||||||
| 98 | # Is a specified object attribute accessible in a given mode | ||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub _accessible { | ||||||||||||||||||||||||||||||
|
Subroutine
_accessible: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 100 | 0 | my ( $self, $attr, $mode ) = @_; | |||||||||||||||||||||||||||||||
| 101 | 0 | $_attr_data{$attr}[1] =~ /$mode/; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | # Classwide default value for a specified object attribute | ||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _default_for { | ||||||||||||||||||||||||||||||
|
Subroutine
_default_for: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 106 | 0 | my ( $self, $attr ) = @_; | |||||||||||||||||||||||||||||||
| 107 | 0 | $_attr_data{$attr}[0]; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | # List of names of all specified object attributes | ||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub _standard_keys { | ||||||||||||||||||||||||||||||
|
Subroutine
_standard_keys: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 112 | 0 | keys %_attr_data; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=10 SCAR=46.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 117 | 0 | my ( $caller, %args ) = @_; | |||||||||||||||||||||||||||||||
| 118 | 0 | my $caller_is_obj = ref( $caller ); | |||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my $class = $caller_is_obj || $caller; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$caller_is_obj || $caller
MC/DC0%0/2
$caller_is_obj || $caller
$caller_is_obj
$caller
Truth table0%0/3
A || B
A= $caller_is_objB= $caller
| |||||||||||||||||||||||||||||||||
| 120 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||
| 121 | 0 | foreach my $attrname ( $self->_standard_keys ) { | |||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( exists $args{$attrname} && defined $args{$attrname} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
exists $args{$attrname} and defined $args{$attrname}
MC/DC0%0/2
exists $args{$attrname} and defined $args{$attrname}
exists $args{$attrname}
defined $args{$attrname}
Truth table0%0/3
A and B
A= exists $args{$attrname}B= defined $args{$attrname}
| |||||||||||||||||||||||||||||||||
| 123 | 0 | $self->{$attrname} = $args{$attrname}; | |||||||||||||||||||||||||||||||
| 124 | } elsif ( $caller_is_obj ) { | ||||||||||||||||||||||||||||||||
| 125 | 0 | $self->{$attrname} = $caller->{$attrname}; | |||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||
| 127 | 0 | $self->{$attrname} = $self->_default_for( $attrname ); | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | # get ontology server if not defined in ENV | ||||||||||||||||||||||||||||||||
| 131 | do { | ||||||||||||||||||||||||||||||||
| 132 | 0 | my ($ontologyserver) = _getOntologyServer(); # get default from moby central | |||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $self->host($ontologyserver) if $ontologyserver; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | } unless $ENV{MOBY_ONTOLOGYSERVER}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | # use the ENV version if it exists | ||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | $self->host($ENV{MOBY_ONTOLOGYSERVER}) if ($ENV{MOBY_ONTOLOGYSERVER}); # override with user preference if set in their environment | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return undef unless $self->host; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub _getOntologyServer { | ||||||||||||||||||||||||||||||
|
Subroutine
_getOntologyServer: not called CC=1 SCAR=0.9
| |||||||||||||||||||||||||||||||||
| 143 | 4 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 144 | 4 | ▶ | use HTTP::Request::Common qw(HEAD); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 145 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||
| 146 | 0 | my $req = HEAD 'http://biomoby.org/ontologyserver'; | |||||||||||||||||||||||||||||||
| 147 | 0 | my $res = $ua->simple_request($req); | |||||||||||||||||||||||||||||||
| 148 | 0 | my $ontologyserver = $res->header('location'); | |||||||||||||||||||||||||||||||
| 149 | 0 | return $ontologyserver; | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | =head2 objectExists | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub objectExists { | ||||||||||||||||||||||||||||||
|
Subroutine
objectExists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 157 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||
| 158 | 0 | my $term = $args{'term'}; | |||||||||||||||||||||||||||||||
| 159 | 0 | $term =~ s/^moby://; # if the term is namespaced, then remove that | |||||||||||||||||||||||||||||||
| 160 | 0 | my $ua = $self->getUserAgent; | |||||||||||||||||||||||||||||||
| 161 | 0 | my $req = HTTP::Request->new( POST => $self->host ); | |||||||||||||||||||||||||||||||
| 162 | 0 | $req->content( "objectExists=$term" ); | |||||||||||||||||||||||||||||||
| 163 | 0 | my $res = $ua->request( $req ); | |||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ( $res->is_success ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | 0 | return split "\n", $res->content; | |||||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||||||
| 167 | 0 | return ( 0, "Request Failed for unknown reasons", "" ); | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | =head2 serviceExists | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub serviceExists { | ||||||||||||||||||||||||||||||
|
Subroutine
serviceExists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 176 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||
| 177 | 0 | my $term = $args{'term'}; | |||||||||||||||||||||||||||||||
| 178 | 0 | $term =~ s/^moby://; # if the term is namespaced, then remove that | |||||||||||||||||||||||||||||||
| 179 | 0 | my $ua = $self->getUserAgent; | |||||||||||||||||||||||||||||||
| 180 | 0 | my $req = HTTP::Request->new( POST => $self->host ); | |||||||||||||||||||||||||||||||
| 181 | 0 | $req->content( "serviceExists=$term" ); | |||||||||||||||||||||||||||||||
| 182 | 0 | my $res = $ua->request( $req ); | |||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( $res->is_success ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | 0 | return split "\n", $res->content; | |||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||
| 186 | 0 | return ( 0, "Request Failed for unknown reasons", "" ); | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | =head2 namespaceExists | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub namespaceExists { | ||||||||||||||||||||||||||||||
|
Subroutine
namespaceExists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 195 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||
| 196 | 0 | my $term = $args{'term'}; | |||||||||||||||||||||||||||||||
| 197 | 0 | $term =~ s/^moby://; # if the term is namespaced, then remove that | |||||||||||||||||||||||||||||||
| 198 | 0 | my $ua = $self->getUserAgent; | |||||||||||||||||||||||||||||||
| 199 | 0 | my $req = HTTP::Request->new( POST => $self->host ); | |||||||||||||||||||||||||||||||
| 200 | 0 | $req->content( "namespaceExists=$term" ); | |||||||||||||||||||||||||||||||
| 201 | 0 | my $res = $ua->request( $req ); | |||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ( $res->is_success ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 203 | 0 | return split "\n", $res->content; | |||||||||||||||||||||||||||||||
| 204 | } else { | ||||||||||||||||||||||||||||||||
| 205 | 0 | return ( 0, "Request Failed for unknown reasons", "" ); | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | =head2 relationshipExists | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | =cut | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub relationshipExists { | ||||||||||||||||||||||||||||||
|
Subroutine
relationshipExists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 214 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||
| 215 | 0 | my $term = $args{'term'}; | |||||||||||||||||||||||||||||||
| 216 | 0 | my $ontology = $args{'ontology'}; | |||||||||||||||||||||||||||||||
| 217 | 0 | $term =~ s/^moby://; # if the term is namespaced, then remove that | |||||||||||||||||||||||||||||||
| 218 | 0 | my $ua = $self->getUserAgent; | |||||||||||||||||||||||||||||||
| 219 | 0 | my $req = HTTP::Request->new( POST => $self->host ); | |||||||||||||||||||||||||||||||
| 220 | 0 | $req->content( "relationshipExists=$term&ontology=$ontology" ); | |||||||||||||||||||||||||||||||
| 221 | 0 | my $res = $ua->request( $req ); | |||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ( $res->is_success ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 223 | 0 | return split "\n", $res->content; | |||||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||||||
| 225 | 0 | return ( 0, "Request Failed for unknown reasons", "" ); | |||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub getUserAgent { | ||||||||||||||||||||||||||||||
|
Subroutine
getUserAgent: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 230 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||
| 231 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||||||||||||||||||||||||
| 232 | 0 | $ua->agent($user_agent); | |||||||||||||||||||||||||||||||
| 233 | my $proxy = $ENV{MOBY_PROXY} | ||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if $ENV{MOBY_PROXY}; # first check the environment | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $proxy = $self->proxy | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 236 | if $self->proxy | ||||||||||||||||||||||||||||||||
| 237 | ; # but if the object was initialized with a proxy argument then use that instead | ||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( $proxy ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 239 | 0 | $ua->proxy( 'http', $proxy ); | |||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||
| 241 | 0 | return $ua; | |||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=27.3
| |||||||||||||||||||||||||||||||||
| 246 | 4 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 247 | 0 | my ( $self, $newval ) = @_; | |||||||||||||||||||||||||||||||
| 248 | 0 | $AUTOLOAD =~ /.*::(\w+)/; | |||||||||||||||||||||||||||||||
| 249 | 0 | my $attr = $1; | |||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ( $self->_accessible( $attr, 'write' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 253 | 0 | return $_[0]->{$attr}; | |||||||||||||||||||||||||||||||
| 254 | 0 | }; ### end of created subroutine | |||||||||||||||||||||||||||||||
| 255 | ### this is called first time only | ||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if ( defined $newval ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 257 | 0 | $self->{$attr} = $newval; | |||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||
| 259 | 0 | return $self->{$attr}; | |||||||||||||||||||||||||||||||
| 260 | } elsif ( $self->_accessible( $attr, 'read' ) ) { | ||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 262 | 0 | return $_[0]->{$attr}; | |||||||||||||||||||||||||||||||
| 263 | 0 | }; ### end of created subroutine | |||||||||||||||||||||||||||||||
| 264 | 0 | return $self->{$attr}; | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | # Must have been a mistake then... | ||||||||||||||||||||||||||||||||
| 268 | 0 | croak "No such method: $AUTOLOAD"; | |||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||
| 270 | 4 | 1; | |||||||||||||||||||||||||||||||