[MOBY-guts] biomoby commit

Frank Gibbons fgibbons at pub.open-bio.org
Fri Sep 2 14:39:21 UTC 2005


fgibbons
Fri Sep  2 10:39:20 EDT 2005
Update of /home/repository/moby/moby-live/Perl/MOBY/Client
In directory pub.open-bio.org:/tmp/cvs-serv10661

Modified Files:
	SimpleArticle.pm 
Log Message:
 - The tests drove out a few bugs:
 	* extraction of lsid from <Simple> element was incorrect.
	* call to the XML method does nothing except set the value of the
	  $self->XML component to the string passed in as the argument.
	  This isn't what you'd expect, since everything else is a get/set
	  method, and setting the XML to a string that doesn't reflect
	  the actual object is not likely to be useful in an API.
	  Solution: Either we remove it from the API, i.e., make it a private
	  method; or we make it do the right thing (see above).
 - Removed redundant 'Title' lines in perldoc.

moby-live/Perl/MOBY/Client SimpleArticle.pm,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/SimpleArticle.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Perl/MOBY/Client/SimpleArticle.pm	2005/07/29 18:58:44	1.8
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/SimpleArticle.pm	2005/09/02 14:39:20	1.9
@@ -53,7 +53,6 @@
 
 =head2 new
 
- Title     :	new
  Usage     :	my $SA = MOBY::Client::SimpleArticle->new(%args)
  Function  :	create SimpleArticle object
  Returns   :	MOBY::Client::SimpleArticle object
@@ -64,81 +63,60 @@
                 XML_DOM => $XML::DOM::NODE
 
 
-=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 objectLSID
 
- Title     :	objectLSID
  Usage     :	$type = $SA->objectLSID($type)
  Function  :	get/set LSID
  Returns   :	string
  Arguments :    (optional) string representing objectLSID 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::SimpleArticle
  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::SimpleArticle
  Arguments :    (optional) an $XML::DOM node from the <Simple> article of a DOM
 
-=cut
 
 =head2 addNamespace
 
- Title     :	addNamespace
  Usage     :	$namespaces = $IN->addNamespace($namespace)
  Function  :	add another namespace for the objectType
  Returns   :	namespace string
 
-=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
@@ -147,11 +125,9 @@
                  to test what you have in-hand)
  Returns   :	1 (true)
 
-=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
@@ -160,11 +136,8 @@
                  to test what you have in-hand)
  Returns   :	0 for false
 
-=cut
-
 =head2 isSecondary
 
- Title     :	isSecondary
  Usage     :	$boolean = $IN->isSecondary()
  Function  :	is this a SecondaryArticle type?
                 (yes, I know this is obvious)
@@ -220,68 +193,65 @@
 }
 
 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 );
-		}
-	}
-	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 );
+    }
+  }
+  if ( $self->XML && ref( $self->XML ) ) {
+    return 0;
+  } elsif ( $self->XML_DOM && !( ref( $self->XML_DOM ) =~ /XML\:\:LibXML/ ) ) {
+    return 0;
+  }
+
+  $self->createFromXML                   if ( $self->XML );
+  $self->createFromDOM( $self->XML_DOM ) if ( $self->XML_DOM );
+  return $self;
 }
 
 sub createFromXML {
-	my ( $self ) = @_;
-	my $p        = XML::LibXML->new;
-	my $doc      = $p->parse_string( $self->XML );
-	my $root     = $doc->getDocumentElement;
-	return 0 unless ( $root && ( $root->nodeName eq "Simple" ) );
-	return $self->createFromDOM( $root );
+  my ( $self ) = @_;
+  my $p        = XML::LibXML->new;
+  my $doc      = $p->parse_string( $self->XML );
+  my $root     = $doc->getDocumentElement;
+  return 0 unless ( $root && ( $root->nodeName eq "Simple" ) );
+  return $self->createFromDOM( $root );
 }
 
 sub createFromDOM {
-	my ( $self, $dom ) = @_;
-	return 0 unless ( $dom && ( $dom->nodeName eq "Simple" ) );
-	$self->XML( $dom->toString );    # set the string version of the DOM
-	$self->namespaces( [] );         # reset!
-	$self->articleName( "" );
-	$self->objectType( "" );
-	my $attr        = $dom->getAttributeNode( 'articleName' );
-	my $lsid        = $dom->getAttributeNode( 'lsid' );
-	my $articleName = "";
-	$articleName = $attr->getValue if $attr;
-        $lsid = $attr->getValue if $lsid;
-        
-	$self->articleName( $articleName )
-	  if $articleName
-	  ; # it may have already been set if this Simple is part of a Collection...
-        $self->objectLSID( $lsid) if $lsid;
-
-# fork here - it may be an instantiated object (coming from a service invocation/response)
-# or it may be a template object as in the SimpleArticle element of a registration call
-# if the objectType tag exists, then it is a template object
-	if ( @{ $dom->getElementsByTagName( "objectType" ) }[0] ) {
-		return $self->_createTemplateArticle( $dom );
-	} else {
-		return $self->_createInstantiatedArticle( $dom );
-	}
-
-	# otherwise it should simpy contain an instantiated MOBY object
+  my ( $self, $dom ) = @_;
+  return 0 unless ( $dom && ( $dom->nodeName eq "Simple" ) );
+  $self->namespaces( [] );         # reset!
+  $self->articleName( "" );
+  $self->objectType( "" );
+  my $attr = $dom->getAttributeNode( 'articleName' );
+  my $articleName = $attr ? $attr->getValue : "";
+  $attr = $dom->getAttributeNode( 'lsid' );
+  my $lsid = $attr ? $attr->getValue : "";
+
+  $self->articleName( $articleName )
+    if $articleName; # it may have already been set if this Simple is part of a Collection...
+  $self->objectLSID( $lsid) if $lsid;
+
+  # fork here - it may be an instantiated object (coming from a service invocation/response)
+  # or it may be a template object as in the SimpleArticle element of a registration call
+  # if the objectType tag exists, then it is a template object
+  if ( @{ $dom->getElementsByTagName( "objectType" ) }[0] ) {
+    return $self->_createTemplateArticle( $dom );
+  } else {
+    return $self->_createInstantiatedArticle( $dom );
+  }
+  # otherwise it should simpy contain an instantiated MOBY object
 }
 
 sub _createInstantiatedArticle {
@@ -333,29 +303,30 @@
 }
 
 sub AUTOLOAD {
-	no strict "refs";
-	my ( $self, $newval ) = @_;
-	$AUTOLOAD =~ /.*::(\w+)/;
-	my $attr = $1;
-	if ( $self->_accessible( $attr, 'write' ) ) {
-		*{$AUTOLOAD} = sub {
-			if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
-			return $_[0]->{$attr};
-		};    ### end of created subroutine
-###  this is called first time only
-		if ( defined $newval ) {
-			$self->{$attr} = $newval;
-		}
-		return $self->{$attr};
-	} elsif ( $self->_accessible( $attr, 'read' ) ) {
-		*{$AUTOLOAD} = sub {
-			return $_[0]->{$attr};
-		};    ### end of created subroutine
-		return $self->{$attr};
-	}
-
-	# Must have been a mistake then...
-	croak "No such method: $AUTOLOAD";
+  # It seems desirable that if the XML() method is called, the XML should be parsed, rather than just being 
+  no strict "refs";
+  my ( $self, $newval ) = @_;
+  $AUTOLOAD =~ /.*::(\w+)/;
+  my $attr = $1;
+  if ( $self->_accessible( $attr, 'write' ) ) {
+    *{$AUTOLOAD} = sub {
+      if ( defined $_[1] ) { $_[0]->{$attr} = $_[1]; }
+      return $_[0]->{$attr};
+    };    ### end of created subroutine
+    ###  this is called first time only
+    if ( defined $newval ) {
+      $self->{$attr} = $newval;
+    }
+    return $self->{$attr};
+  } elsif ( $self->_accessible( $attr, 'read' ) ) {
+    *{$AUTOLOAD} = sub {
+      return $_[0]->{$attr};
+    };    ### end of created subroutine
+    return $self->{$attr};
+  }
+  
+  # Must have been a mistake then...
+  croak "No such method: $AUTOLOAD";
 }
 sub DESTROY { }
 1;




More information about the MOBY-guts mailing list