| 1 | package MOBY::Client::SimpleInput; | ||
| 2 | use strict; | ||
| 3 | use Carp; | ||
| 4 | use vars qw($AUTOLOAD @ISA); | ||
| 5 | |||
| 6 | use vars qw /$VERSION/; | ||
| 7 | $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | MOBY::Client::SimpleInput - a small object describing a MOBY service | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | A module for describing the Simple inputs to a moby service | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | =head1 AUTHORS | ||
| 24 | |||
| 25 | Mark Wilkinson (markw at illuminae dot com) | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | =head1 METHODS | ||
| 30 | |||
| 31 | |||
| 32 | =head2 new | ||
| 33 | |||
| 34 | Title : new | ||
| 35 | Usage : my $IN = MOBY::Client::SimpleInput->new(%args) | ||
| 36 | Function : create SimpleInput object | ||
| 37 | Returns : MOBY::Client::SimpleInput object | ||
| 38 | Args : articleName => $articleName (optional) | ||
| 39 | objectType => $objectType (required) | ||
| 40 | namespaces => \@namesapces (optional) | ||
| 41 | =cut | ||
| 42 | |||
| 43 | =head2 articleName | ||
| 44 | |||
| 45 | Title : articleName | ||
| 46 | Usage : $name = $IN->articleName([$name]) | ||
| 47 | Function : get/set articleName | ||
| 48 | Returns : string | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | =head2 objectType | ||
| 53 | |||
| 54 | Title : objectType | ||
| 55 | Usage : $type = $IN->objectType([$type]) | ||
| 56 | Function : get/set name | ||
| 57 | Returns : string | ||
| 58 | |||
| 59 | =cut | ||
| 60 | |||
| 61 | =head2 namespaces | ||
| 62 | |||
| 63 | Title : namespaces | ||
| 64 | Usage : $namespaces = $IN->namespaces([\@namespaces]) | ||
| 65 | Function : get/set namespaces for the objectType | ||
| 66 | Returns : arrayref of namespace strings | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | =head2 addNamespace | ||
| 71 | |||
| 72 | Title : addNamespace | ||
| 73 | Usage : $namespaces = $IN->addNamespace($namespace) | ||
| 74 | Function : add another namespace for the objectType | ||
| 75 | Returns : arrayref of namespace strings | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | { | ||
| 80 | |||
| 81 | # Encapsulated: | ||
| 82 | # DATA | ||
| 83 | #___________________________________________________________ | ||
| 84 | #ATTRIBUTES | ||
| 85 | my %_attr_data = # DEFAULT ACCESSIBILITY | ||
| 86 | ( | ||
| 87 | articleName => [ undef, 'read/write' ], | ||
| 88 | objectType => [ undef, 'read/write' ], | ||
| 89 | namespaces => [ undef, 'read/write' ], | ||
| 90 | ); | ||
| 91 | |||
| 92 | #_____________________________________________________________ | ||
| 93 | # METHODS, to operate on encapsulated class data | ||
| 94 | # Is a specified object attribute accessible in a given mode | ||
| 95 | sub _accessible { | ||
| 96 | my ( $self, $attr, $mode ) = @_; | ||
| 97 | $_attr_data{$attr}[1] =~ /$mode/; | ||
| 98 | } | ||
| 99 | |||
| 100 | # Classwide default value for a specified object attribute | ||
| 101 | sub _default_for { | ||
| 102 | my ( $self, $attr ) = @_; | ||
| 103 | $_attr_data{$attr}[0]; | ||
| 104 | } | ||
| 105 | |||
| 106 | # List of names of all specified object attributes | ||
| 107 | sub _standard_keys { | ||
| 108 | keys %_attr_data; | ||
| 109 | } | ||
| 110 | |||
| 111 | sub addNamespace { | ||
| 112 | my ( $self, $ns ) = @_; | ||
| 113 | return $self->{namespaces} unless $ns; | ||
| 114 | push @{ $self->{namespaces} }, $ns; | ||
| 115 | return $self->{namespaces}; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | sub new { | ||
| 120 | my ( $caller, %args ) = @_; | ||
| 121 | my $caller_is_obj = ref( $caller ); | ||
| 122 | return $caller if $caller_is_obj; | ||
| 123 | my $class = $caller_is_obj || $caller; | ||
| 124 | my $proxy; | ||
| 125 | my $self = bless {}, $class; | ||
| 126 | foreach my $attrname ( $self->_standard_keys ) { | ||
| 127 | if ( exists $args{$attrname} ) { | ||
| 128 | $self->{$attrname} = $args{$attrname}; | ||
| 129 | } elsif ( $caller_is_obj ) { | ||
| 130 | $self->{$attrname} = $caller->{$attrname}; | ||
| 131 | } else { | ||
| 132 | $self->{$attrname} = $self->_default_for( $attrname ); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | return $self; | ||
| 136 | } | ||
| 137 | |||
| 138 | sub AUTOLOAD { | ||
| 139 | no strict "refs"; | ||
| 140 | my ( $self, $newval ) = @_; | ||
| 141 | $AUTOLOAD =~ /.*::(\w+)/; | ||
| 142 | my $attr = $1; | ||
| 143 | if ( $self->_accessible( $attr, 'write' ) ) { | ||
| 144 | *{$AUTOLOAD} = sub { | ||
| 145 | if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] } | ||
| 146 | return $_[0]->{$attr}; | ||
| 147 | }; ### end of created subroutine | ||
| 148 | ### this is called first time only | ||
| 149 | if ( defined $newval ) { | ||
| 150 | $self->{$attr} = $newval; | ||
| 151 | } | ||
| 152 | return $self->{$attr}; | ||
| 153 | } elsif ( $self->_accessible( $attr, 'read' ) ) { | ||
| 154 | *{$AUTOLOAD} = sub { | ||
| 155 | return $_[0]->{$attr}; | ||
| 156 | }; ### end of created subroutine | ||
| 157 | return $self->{$attr}; | ||
| 158 | } | ||
| 159 | |||
| 160 | # Must have been a mistake then... | ||
| 161 | croak "No such method: $AUTOLOAD"; | ||
| 162 | } | ||
| 163 | sub DESTROY { } | ||
| 164 | 1; |