Update of /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries
In directory usw-pr-cvs1:/tmp/cvs-serv22998
Modified Files:
ControlStructuresLibrary.pm
Log Message:
* added <ns:fail>-tag
Index: ControlStructuresLibrary.pm
===================================================================
RCS file: /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries/ControlStructuresLibrary.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** ControlStructuresLibrary.pm 26 Oct 2002 21:17:13 -0000 1.13
--- ControlStructuresLibrary.pm 29 Oct 2002 10:31:44 -0000 1.14
***************
*** 101,104 ****
--- 101,112 ----
# in the document, the faster the processing will be.
# </p>
+ # <p>
+ # There may be points in your program, where you want to terminate the
+ # script with a fatal error. The following tag can be used for this:
+ # <pre>
+ # <ns:fail message="your error message here"/>
+ # </pre>
+ # This will terminate the script with a fatal error, displaying the
+ # given error message.
#*/
package NetScript::Libraries::ControlStructuresLibrary;
***************
*** 173,197 ****
if ( $node -> getNamespaceURI() eq $NetScript::Interpreter::NAMESPACE_URI ) {
! if ($node -> getLocalName() eq "if") {
$this -> ifStart( $domWalker, $node );
return 0; # consume event
}
! elsif( $node -> getLocalName() eq "else" ) {
$this -> elseStart( $domWalker, $node );
return 0; # consume event
}
! elsif ($node -> getLocalName() eq "while" ) {
$this -> whileStart( $domWalker, $node );
return 0; # consume event
}
! elsif ($node -> getLocalName() eq "for" ) {
$this -> forStart( $domWalker, $node );
return 0; # consume event
}
! elsif( $node -> getLocalName() eq "ignore" ) {
# Walk over the node
$domWalker -> stepSourceIn();
return 0; #consume event
}
}
return 1; # do not consume event
--- 181,210 ----
if ( $node -> getNamespaceURI() eq $NetScript::Interpreter::NAMESPACE_URI ) {
! my $localName = $node -> getLocalName();
! if ( $localName eq "if") {
$this -> ifStart( $domWalker, $node );
return 0; # consume event
}
! elsif( $localName eq "else" ) {
$this -> elseStart( $domWalker, $node );
return 0; # consume event
}
! elsif ( $localName eq "while" ) {
$this -> whileStart( $domWalker, $node );
return 0; # consume event
}
! elsif ( $localName eq "for" ) {
$this -> forStart( $domWalker, $node );
return 0; # consume event
}
! elsif( $localName eq "ignore" ) {
# Walk over the node
$domWalker -> stepSourceIn();
return 0; #consume event
}
+ elsif( $localName eq "fail" ) {
+ $this -> doFail( $domWalker, $node );
+ return 0;
+ }
}
return 1; # do not consume event
***************
*** 199,202 ****
--- 212,231 ----
#/**
+ # Raises a fatal error.
+ # @param an instance of NetScript::Engine::DOMWalker
+ # @param the if-node (XML::DOM2::Element)
+ # @private
+ #*/
+ sub doFail {
+ my ( $this, $domWalker, $node ) = @_;
+ my $msg = $node -> getAttribute( "message" );
+ $msg = $this -> interpreter() -> getStatementEvaluator() ->
+ evaluateStatement( $msg );
+ # raise fatal error
+ $this -> interpreter() -> getEventRelay() -> createAndRaiseEvent(
+ $NetScript::Interpreter::FATAL_EVENT, $msg );
+ }
+
+ #/**
# Checks the test-attribute of the given element node
# for being true or false.
***************
*** 429,432 ****
--- 458,462 ----
my $node = $domWalker -> currentSource();
if ( $node -> getNamespaceURI() eq $NetScript::Interpreter::NAMESPACE_URI ) {
+ my $localName = $node -> getLocalName();
if ($node -> getLocalName() eq "if") {
# kill state
***************
*** 450,453 ****
--- 480,487 ----
return 0; #consume event
}
+ elsif( $localName eq "fail" ) { #should never be called...
+ return 0; #consume event
+ }
+
}
return 1; # do not consume event
|