fixing a problem with empty/duplicated roles upon account creation
[cxgn-corelibs.git] / lib / MOBY / Client / SimpleInput.pm
blob3b9c4d83cff2897e7472e1dd19dfc45f9c52d02a
1 package MOBY::Client::SimpleInput;
2 use strict;
3 use Carp;
4 use vars qw($AUTOLOAD @ISA);
6 =head1 NAME
8 MOBY::Client::SimpleInput - a small object describing a MOBY service
10 =head1 SYNOPSIS
12 =cut
14 =head1 DESCRIPTION
16 =head1 AUTHORS
18 =cut
20 =head1 METHODS
23 =head2 new
25 Title : new
26 Usage : my $IN = MOBY::Client::SimpleInput->new(%args)
27 Function : create SimpleInput object
28 Returns : MOBY::Client::SimpleInput object
29 Args : articleName => $articleName (optional)
30 objectType => $objectType (required)
31 namespaces => \@namesapces (optional)
32 =cut
34 =head2 articleName
36 Title : articleName
37 Usage : $name = $IN->articleName([$name])
38 Function : get/set articleName
39 Returns : string
41 =cut
43 =head2 objectType
45 Title : objectType
46 Usage : $type = $IN->objectType([$type])
47 Function : get/set name
48 Returns : string
50 =cut
52 =head2 namespaces
54 Title : namespaces
55 Usage : $namespaces = $IN->namespaces([\@namespaces])
56 Function : get/set namespaces for the objectType
57 Returns : arrayref of namespace strings
59 =cut
61 =head2 addNamespace
63 Title : addNamespace
64 Usage : $namespaces = $IN->addNamespace($namespace)
65 Function : add another namespace for the objectType
66 Returns : arrayref of namespace strings
68 =cut
72 # Encapsulated:
73 # DATA
74 #___________________________________________________________
75 #ATTRIBUTES
76 my %_attr_data = # DEFAULT ACCESSIBILITY
78 articleName => [ undef, 'read/write' ],
79 objectType => [ undef, 'read/write' ],
80 namespaces => [ [], 'read/write' ],
83 #_____________________________________________________________
84 # METHODS, to operate on encapsulated class data
85 # Is a specified object attribute accessible in a given mode
86 sub _accessible {
87 my ( $self, $attr, $mode ) = @_;
88 $_attr_data{$attr}[1] =~ /$mode/;
91 # Classwide default value for a specified object attribute
92 sub _default_for {
93 my ( $self, $attr ) = @_;
94 $_attr_data{$attr}[0];
97 # List of names of all specified object attributes
98 sub _standard_keys {
99 keys %_attr_data;
102 sub addNamespace {
103 my ( $self, $ns ) = @_;
104 return $self->{namespaces} unless $ns;
105 push @{ $self->{namespaces} }, $ns;
106 return $self->{namespaces};
110 sub new {
111 my ( $caller, %args ) = @_;
112 my $caller_is_obj = ref( $caller );
113 return $caller if $caller_is_obj;
114 my $class = $caller_is_obj || $caller;
115 my $proxy;
116 my $self = bless {}, $class;
117 foreach my $attrname ( $self->_standard_keys ) {
118 if ( exists $args{$attrname} ) {
119 $self->{$attrname} = $args{$attrname};
120 } elsif ( $caller_is_obj ) {
121 $self->{$attrname} = $caller->{$attrname};
122 } else {
123 $self->{$attrname} = $self->_default_for( $attrname );
126 return $self;
129 sub AUTOLOAD {
130 no strict "refs";
131 my ( $self, $newval ) = @_;
132 $AUTOLOAD =~ /.*::(\w+)/;
133 my $attr = $1;
134 if ( $self->_accessible( $attr, 'write' ) ) {
135 *{$AUTOLOAD} = sub {
136 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
137 return $_[0]->{$attr};
138 }; ### end of created subroutine
139 ### this is called first time only
140 if ( defined $newval ) {
141 $self->{$attr} = $newval;
143 return $self->{$attr};
144 } elsif ( $self->_accessible( $attr, 'read' ) ) {
145 *{$AUTOLOAD} = sub {
146 return $_[0]->{$attr};
147 }; ### end of created subroutine
148 return $self->{$attr};
151 # Must have been a mistake then...
152 croak "No such method: $AUTOLOAD";
154 sub DESTROY { }