| 1 | #!/usr/bin/perl -w | ||
| 2 | package MOBY::service_type; | ||
| 3 | use strict; | ||
| 4 | use Carp; | ||
| 5 | use vars qw($AUTOLOAD @ISA); | ||
| 6 | |||
| 7 | use vars qw /$VERSION/; | ||
| 8 | $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | MOBY::service_type - a lightweight connection to the | ||
| 13 | service_type table in the database | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | use MOBY::service_type; | ||
| 18 | my $Instance = MOBY::service_type->new( | ||
| 19 | rdf_definition => "URI:LSID:www.biomoby.org:services:Blast", | ||
| 20 | name "Blast", | ||
| 21 | ); | ||
| 22 | print $Instance->service_type_id; | ||
| 23 | |||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | representation of the service_type table. Can write to the database | ||
| 30 | |||
| 31 | =head1 AUTHORS | ||
| 32 | |||
| 33 | Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca) | ||
| 34 | |||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | { | ||
| 39 | |||
| 40 | # Encapsulated: | ||
| 41 | # DATA | ||
| 42 | #___________________________________________________________ | ||
| 43 | #ATTRIBUTES | ||
| 44 | my %_attr_data = # DEFAULT ACCESSIBILITY | ||
| 45 | ( | ||
| 46 | service_type_id => [ undef, 'read/write' ], | ||
| 47 | rdf_definition => [ undef, 'read/write' ], | ||
| 48 | ); | ||
| 49 | |||
| 50 | #_____________________________________________________________ | ||
| 51 | # METHODS, to operate on encapsulated class data | ||
| 52 | # Is a specified object attribute accessible in a given mode | ||
| 53 | sub _accessible { | ||
| 54 | my ( $self, $attr, $mode ) = @_; | ||
| 55 | $_attr_data{$attr}[1] =~ /$mode/; | ||
| 56 | } | ||
| 57 | |||
| 58 | # Classwide default value for a specified object attribute | ||
| 59 | sub _default_for { | ||
| 60 | my ( $self, $attr ) = @_; | ||
| 61 | $_attr_data{$attr}[0]; | ||
| 62 | } | ||
| 63 | |||
| 64 | # List of names of all specified object attributes | ||
| 65 | sub _standard_keys { | ||
| 66 | keys %_attr_data; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | sub new { | ||
| 71 | my ( $caller, %args ) = @_; | ||
| 72 | my $caller_is_obj = ref($caller); | ||
| 73 | return $caller if $caller_is_obj; | ||
| 74 | my $class = $caller_is_obj || $caller; | ||
| 75 | my $proxy; | ||
| 76 | my $self = bless {}, $class; | ||
| 77 | foreach my $attrname ( $self->_standard_keys ) { | ||
| 78 | if ( exists $args{$attrname} ) { | ||
| 79 | $self->{$attrname} = $args{$attrname}; | ||
| 80 | } elsif ($caller_is_obj) { | ||
| 81 | $self->{$attrname} = $caller->{$attrname}; | ||
| 82 | } else { | ||
| 83 | $self->{$attrname} = $self->_default_for($attrname); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | return $self; | ||
| 87 | } | ||
| 88 | |||
| 89 | sub AUTOLOAD { | ||
| 90 | no strict "refs"; | ||
| 91 | my ( $self, $newval ) = @_; | ||
| 92 | $AUTOLOAD =~ /.*::(\w+)/; | ||
| 93 | my $attr = $1; | ||
| 94 | if ( $self->_accessible( $attr, 'write' ) ) { | ||
| 95 | *{$AUTOLOAD} = sub { | ||
| 96 | if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] } | ||
| 97 | return $_[0]->{$attr}; | ||
| 98 | }; ### end of created subroutine | ||
| 99 | ### this is called first time only | ||
| 100 | if ( defined $newval ) { | ||
| 101 | $self->{$attr} = $newval; | ||
| 102 | } | ||
| 103 | return $self->{$attr}; | ||
| 104 | } elsif ( $self->_accessible( $attr, 'read' ) ) { | ||
| 105 | *{$AUTOLOAD} = sub { | ||
| 106 | return $_[0]->{$attr}; | ||
| 107 | }; ### end of created subroutine | ||
| 108 | return $self->{$attr}; | ||
| 109 | } | ||
| 110 | |||
| 111 | # Must have been a mistake then... | ||
| 112 | croak "No such method: $AUTOLOAD"; | ||
| 113 | } | ||
| 114 | sub DESTROY { } | ||
| 115 | 1; |