[MOBY-guts] biomoby commit
Frank Gibbons
fgibbons at pub.open-bio.org
Tue Sep 6 20:28:34 UTC 2005
fgibbons
Tue Sep 6 16:28:34 EDT 2005
Update of /home/repository/moby/moby-live/Perl/MOBY/Client
In directory pub.open-bio.org:/tmp/cvs-serv4175/MOBY/Client
Modified Files:
SecondaryArticle.pm
Log Message:
- Clean up code, replace duplicate blocks of code (default/datatype/max/min) with single generic.
moby-live/Perl/MOBY/Client SecondaryArticle.pm,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/SecondaryArticle.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Perl/MOBY/Client/SecondaryArticle.pm 2004/12/14 22:31:30 1.6
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/SecondaryArticle.pm 2005/09/06 20:28:34 1.7
@@ -22,14 +22,11 @@
Mark Wilkinson (markw at illuminae dot com)
-=cut
-
=head1 METHODS
=head2 new
- Title : new
Usage : my $SA = MOBY::Client::SecondaryArticle->new(%args)
Function : create SecondaryArticle object
Returns : MOBY::Client::SecondaryArticle object
@@ -42,90 +39,57 @@
XML_DOM => $XML_DOM node of the Secondary article (optional)
XML => $XML XML string representing the Secondary article (optional)
-=cut
-
=head2 articleName
- Title : articleName
Usage : $name = $SA->articleName($name)
Function : get/set articleName
Returns : string
Arguments : (optional) string representing articleName to set
-=cut
-
=head2 objectType
- Title : objectType
Usage : $type = $SA->objectType($type)
Function : get/set name
Returns : string
Arguments : (optional) string representing objectType to set
-=cut
-
=head2 namespaces
- Title : namespaces
Usage : $namespaces = $SA->namespaces(\@namespaces)
Function : get/set namespaces for the objectType
Returns : arrayref of namespace strings
Arguments : (optional) arrayref of namespace strings to set
-=cut
-
=head2 XML
- Title : XML
Usage : $SA = $SA->XML($XML)
Function : set/reset all parameters for this object from the XML
Returns : MOBY::Client::SecondaryArticle
Arguments : (optional) XML fragment from and including <Simple>...</Simple>
-=cut
-
=head2 XML_DOM
- Title : XML_DOM
Usage : $namespaces = $SA->XML_DOM($XML_DOM_NODE)
Function : set/reset all parameters for this object from the XML::DOM node for <Simple>
Returns : MOBY::Client::SecondaryArticle
Arguments : (optional) an $XML::DOM node from the <Simple> article of a DOM
-=cut
-
=head2 isSecondary
- Title : isSecondary
Usage : $boolean = $IN->isSecondary()
- Function : is this a SecondaryArticle type?
- (yes, I know this is obvious)
+ Function : is this a SecondaryArticle type? (yes, I know this is obvious)
Returns : 1 (true)
-=cut
-
=head2 isSimple
- Title : isSimple
Usage : $boolean = $IN->isSimple()
Function : is this a SimpleArticle type
- (yes, I know this is obvious, but since you can
- get both Simple and Collection objects in your
- Input and output lists, it is good to be able
- to test what you have in-hand)
Returns : 0 (false)
-=cut
-
=head2 isCollection
- Title : isCollection
Usage : $boolean = $IN->isCollection()
Function : is this a CollectionArticle type
- (yes, I know this is obvious, but since you can
- get both Simple and Collection objects in your
- Input and output lists, it is good to be able
- to test what you have in-hand)
Returns : 0 for false
=cut
@@ -136,11 +100,11 @@
# DATA
#___________________________________________________________
#ATTRIBUTES
- my %_attr_data = # DEFAULT ACCESSIBILITY
+ my %_attr_data = # DEFAULT ACCESSIBILITY
(
- articleName => [ undef, 'read/write' ],
- objectType => [ undef, 'read/write' ],
- namespaces => [ [], 'read/write' ],
+ articleName => [ undef, 'read/write' ],
+ objectType => [ undef, 'read/write' ],
+ namespaces => [ [], 'read/write' ],
XML_DOM => [ undef, 'read/write' ],
XML => [ undef, 'read/write' ],
isSecondary => [ 1, 'read' ],
@@ -174,39 +138,39 @@
}
sub addEnum {
- my ( $self, $enum ) = @_;
- $self->{enum} = [] unless $self->{enum};
- return $self->{enum} unless defined( $enum );
- push @{ $self->{enum} }, $enum;
- return $self->{enum};
+ # No return value necessary
+ my ( $self, $enum ) = @_;
+ $self->{enum} = [] unless $self->{enum};
+ return() unless defined ($enum);
+ push @{ $self->{enum} }, $enum;
}
}
sub new {
- my ( $caller, %args ) = @_;
- my $caller_is_obj = ref( $caller );
- return $caller if $caller_is_obj;
- my $class = $caller_is_obj || $caller;
- my $proxy;
- my $self = bless {}, $class;
- foreach my $attrname ( $self->_standard_keys ) {
- if ( exists $args{$attrname} ) {
- $self->{$attrname} = $args{$attrname};
- } elsif ( $caller_is_obj ) {
- $self->{$attrname} = $caller->{$attrname};
- } else {
- $self->{$attrname} = $self->_default_for( $attrname );
- }
- }
- $self->{enum} = [] unless $self->enum;
- if ( $self->XML && ref( $self->XML ) ) {
- return 0;
- } elsif ( $self->XML_DOM && !( ref( $self->XML_DOM ) =~ /libxml/i ) ) {
- return 0;
- }
- $self->createFromXML if ( $self->XML );
- $self->createFromDOM( $self->XML_DOM ) if ( $self->XML_DOM );
- return $self;
+ my ( $caller, %args ) = @_;
+ my $caller_is_obj = ref( $caller );
+ return $caller if $caller_is_obj;
+ my $class = $caller_is_obj || $caller;
+ my $proxy;
+ my $self = bless {}, $class;
+ foreach my $attrname ( $self->_standard_keys ) {
+ if ( exists $args{$attrname} ) {
+ $self->{$attrname} = $args{$attrname};
+ } elsif ( $caller_is_obj ) {
+ $self->{$attrname} = $caller->{$attrname};
+ } else {
+ $self->{$attrname} = $self->_default_for( $attrname );
+ }
+ }
+ $self->{enum} = [] unless $self->enum;
+ if ( $self->XML && ref( $self->XML ) ) {
+ return 0;
+ } elsif ( $self->XML_DOM && !( ref( $self->XML_DOM ) =~ /libxml/i ) ) {
+ return 0;
+ }
+ $self->createFromXML if ( $self->XML );
+ $self->createFromDOM( $self->XML_DOM ) if ( $self->XML_DOM );
+ return $self;
}
sub createFromXML {
@@ -226,91 +190,66 @@
$self->articleName( "" );
$self->objectType( "" );
my $attr = $dom->getAttributeNode( 'articleName' );
- my $articleName = "";
- $articleName = $attr->getValue if $attr;
- $self->articleName( $articleName );
-
+ $self->articleName( $attr ? $attr->getValue : "" );
if ( @{ $dom->getElementsByTagName( 'Value' ) }[0] ) {
- return $self->_createInstantiatedArticle( $dom );
+ return $self->_createInstantiatedArticle( $dom );
} else {
- return $self->_createTemplateArticle( $dom );
+ return $self->_createTemplateArticle( $dom );
}
}
sub _createTemplateArticle {
- my ( $self, $dom ) = @_;
+ my ( $self, $dom ) = @_;
- #datatype => [undef, 'read/write' ],
- #default => [undef, 'read/write' ],
- #max => [undef, 'read/write' ],
- #min => [undef, 'read/write' ],
- #enum => [[], 'read/write' ],
- my $objects = $dom->getElementsByTagName( "datatype" );
- if ( $objects->get_node( 1 ) ) {
- my $data;
- foreach my $child ( $objects->get_node( 1 )->childNodes ) {
- next unless $child->nodeType == TEXT_NODE;
- $data .= $child->toString;
- $data =~ s/\s//g;
- }
- $self->datatype( $data );
- }
- $objects = $dom->getElementsByTagName( "default" );
- if ( $objects->get_node( 1 ) ) {
- my $def;
- foreach my $child ( $objects->get_node( 1 )->childNodes ) {
- next unless $child->nodeType == TEXT_NODE;
- $def .= $child->toString;
- $def =~ s/\s//g;
- }
- $self->default( $def );
- }
- $objects = $dom->getElementsByTagName( "max" );
- if ( $objects->get_node( 1 ) ) {
- my $max;
- foreach my $child ( $objects->get_node( 1 )->childNodes ) {
- next unless $child->nodeType == TEXT_NODE;
- $max .= $child->toString;
- $max =~ s/\s//g;
- }
- $self->max( $max );
- }
- $objects = $dom->getElementsByTagName( "min" );
- if ( $objects->get_node( 1 ) ) {
- my $min;
- foreach my $child ( $objects->get_node( 1 )->childNodes ) {
- next unless $child->nodeType == TEXT_NODE;
- $min .= $child->toString;
- $min =~ s/\s//g;
- }
- $self->min( $min );
- }
- $objects = $dom->getElementsByTagName( "enum" );
- if ( $objects->get_node( 1 ) ) {
- foreach ( 1 .. $objects->size() ) {
- foreach my $child ( $objects->get_node( $_ )->childNodes ) {
- my $val;
- next unless $child->nodeType == TEXT_NODE;
- $val = $child->toString;
- next unless defined( $val );
- $val =~ s/^\s//;
- $val =~ s/\s$//;
- $self->addEnum( $val );
- }
- }
- }
- return $self;
+ #datatype => [undef, 'read/write' ],
+ #default => [undef, 'read/write' ],
+ #max => [undef, 'read/write' ],
+ #min => [undef, 'read/write' ],
+ #enum => [[], 'read/write' ],
+ my @single_valued = qw/datatype default max min/;
+ my $objects;
+ foreach my $param (@single_valued) {
+ $objects = $dom->getElementsByTagName( $param );
+ if ( $objects->get_node( 1 ) ) {
+ my $data;
+ foreach my $child ( $objects->get_node( 1 )->childNodes ) {
+ next unless $child->nodeType == TEXT_NODE;
+ $data .= $child->toString;
+ $data =~ s/\s//g; # Trim all whitespace
+ }
+ $self->$param( $data );
+ }
+ }
+ # Since it is (array)multi-valued, 'enum' is a little different from the others.
+ $objects = $dom->getElementsByTagName( "enum" );
+ if ( $objects->get_node( 1 ) ) {
+ foreach ( 1 .. $objects->size() ) {
+ foreach my $child ( $objects->get_node( $_ )->childNodes ) {
+ my $val;
+ next unless $child->nodeType == TEXT_NODE;
+ $val = $child->toString;
+ next unless defined( $val );
+ # Trim space from front and back, but leave alone in middle....?
+ $val =~ s/^\s//;
+ $val =~ s/\s$//;
+ $self->addEnum( $val );
+ }
+ }
+ }
+ return $self;
}
sub _createInstantiatedArticle {
- my ( $self, $dom ) = @_;
+ my ( $self, $dom ) = @_;
- #<Parameter articleName='foo'><Value>43764</Value></Parameter>
- my $values = $dom->getElementsByTagName( 'Value' );
- foreach my $child ( $values->get_node( 1 )->childNodes ) {
- next unless $child->nodeType == TEXT_NODE;
- $self->value( $self->value . $child->toString );
- }
+ #<Parameter articleName='foo'><Value>43764</Value></Parameter>
+ my $values = $dom->getElementsByTagName( 'Value' );
+ $self->value( "" ); # Initialize to 1) avoid Perl warnings 2) be good.
+ foreach my $child ( $values->get_node( 1 )->childNodes ) {
+ next unless $child->nodeType == TEXT_NODE;
+ # Would we *really* want to catenate values like this?
+ $self->value( $self->value . $child->toString );
+ }
}
sub AUTOLOAD {
More information about the MOBY-guts
mailing list