From: Jan T. <de...@us...> - 2002-04-08 21:30:23
|
Update of /cvsroot/net-script/netscript2/src/perl/NetScript/Engine In directory usw-pr-cvs1:/tmp/cvs-serv2614 Modified Files: Class.pm Statement.pm Added Files: BasicStatement.pm StatementEvaluator.pm Log Message: * added BasicStatement, a simple statement copier * added StatementEvaluator, a class for evaluation of in-text-statements * several bugfixes --- NEW FILE: BasicStatement.pm --- #-------------------------------------------------------- # $Id: BasicStatement.pm,v 1.1 2002/04/08 21:30:14 derkork Exp $ # # Class BasicStatement # # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... #-------------------------------------------------------- use strict; #/** # The basic statement is a pure copy statement. It copies # all incoming DOM Nodes to the final DOM and replaces # variables within text nodes, comments, attributes and processing # instructions. As all Statements it is used as a state machine # and only one instance of it lives within the Interpreter. This # saves memory. # #*/ package NetScript::Engine::BasicStatement; use base qw(NetScript::Engine::Statement); use vars qw($VERSION); use XML::DOM2::Node; #-------------------------------------------------------- # Globals #-------------------------------------------------------- $VERSION = '1.0'; #/** # Ctor. #*/ sub new { my ($proto, $argsRef) = @_; my $proto = shift; # get Prototype my $class = ref( $proto ) || $proto;# get the Classname my $this = $class -> SUPER::new(); return $this; # return Object } #/** # Initialises the copy statement. # @param an instance of Netscript::Interpreter # @param an instance of XML::DOM2::Node or one of it's descendants # @param an instance of XML::DOM2::Document (the target document) # @return the this pointer of the statement #*/ sub init { my ( $this, $interpreter, $node, $document ) = @_; $this -> { m_node } = $node; $this -> { m_document } = $document; $this -> { m_interpreter } = $interpreter; $this -> SUPER::init(); } #/** # Returns a copy of the node. Additionally replaces # variables in text nodes, # @return the value of the statement # @abstract #*/ sub evaluate { my ($this) = @_; my $node = $this -> { m_node }; my $document = $this -> { m_document }; my $interpreter = $this -> { m_interpreter }; # clone the node into the new document my $newNode = $document -> importNode( { importedNode => $node, deep => 0 } ); # Check for the Node Type. # TODO # return new node... $this -> setValue( $newNode ); $this -> SUPER::evaluate(); $newNode; } 1; # make "require" happy --- NEW FILE: StatementEvaluator.pm --- #-------------------------------------------------------- # $Id: StatementEvaluator.pm,v 1.1 2002/04/08 21:30:14 derkork Exp $ # # Class Class # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. # (C) 2000-2002 by Jan Thomä, insOMnia # mailto: ko...@in... #-------------------------------------------------------- use strict; #/** # This class represents a Class. #*/ package NetScript::Engine::Class; use vars qw($VERSION); use NetScript::Interpreter; #-------------------------------------------------------- # Globals #-------------------------------------------------------- $VERSION = '1.0'; #/** # Ctor. # @param an instance of NetScript::Interpreter # @public #*/ sub new { my ($proto, $interpreter) = @_; my $proto = shift; # get Prototype my $class = ref( $proto ) || $proto;# get the Classname my $this = {}; bless( $this, $class ); # create Object $this -> { m_interpreter } = @_; return $this; # return Object } #/** # Evaluates the given Statement and returns the evaluated statement. # @param a string holding a statement # @return a string with the evaluated statement # @public #*/ sub evaluateStatement { my ($this, $statement) = @_; $statement =~ s/\$\(test\)/TEST/g; $statement; } #/** # Returns the value of a variable. # @protected #*/ sub getVariableValue { my ($this, $variable) = @_; } #/** # Returns the result of a function # @param the name of the function # @param the argument to the function # @return the value of the function. # @protected #*/ sub getFunctionResult { my ($this, $function, $arg ) = @_; } 1; # make "require" happy Index: Class.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/NetScript/Engine/Class.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Class.pm 1 Apr 2002 20:30:56 -0000 1.1 --- Class.pm 8 Apr 2002 21:30:14 -0000 1.2 *************** *** 2,6 **** # $Id$ # ! # Class Event # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. --- 2,6 ---- # $Id$ # ! # Class Class # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. *************** *** 34,39 **** my %members = (); $this -> { m_Name } = ""; # Classname ! $this -> { m_Functions } = \@functions; # Functions ! $this -> { m_Members } = \@members; # members return $this; # return Object --- 34,39 ---- my %members = (); $this -> { m_Name } = ""; # Classname ! $this -> { m_Functions } = \%functions; # Functions ! $this -> { m_Members } = \%members; # members return $this; # return Object Index: Statement.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/NetScript/Engine/Statement.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Statement.pm 8 Apr 2002 17:35:41 -0000 1.2 --- Statement.pm 8 Apr 2002 21:30:14 -0000 1.3 *************** *** 2,6 **** # $Id$ # ! # Class Event # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. --- 2,6 ---- # $Id$ # ! # Class Statement # NetScript and all related materials, such as documentation, # are protected under the terms and conditions of the Artistic License. *************** *** 25,28 **** --- 25,29 ---- #/** # Ctor. + # @abstract #*/ sub new { *************** *** 33,36 **** --- 34,39 ---- my $this = {}; bless( $this, $class ); # create Object + $this -> { m_executed } = 0; + $this -> { m_value } = undef; return $this; # return Object } *************** *** 39,46 **** #/** # Initialises the statement. The parameters depend ! # on the type of the statement. # @abstract #*/ sub init { undef; } --- 42,54 ---- #/** # Initialises the statement. The parameters depend ! # on the type of the statement. Subclasses should call this ! # sub at the end of their overridden versions of this ! # sub. # @abstract + # @public #*/ sub init { + my ($this) = @_; + $this -> { m_executed } = 0; undef; } *************** *** 48,57 **** #/** # Executes the statement and returns the value of the ! # statement. The value can be void (undef) # @return the value of the statement # @abstract #*/ sub evaluate { ! undef; } --- 56,94 ---- #/** # Executes the statement and returns the value of the ! # statement. The value can be void (undef). Subclasses ! # should call this sub at the end of their overridden ! # versions of this sub. # @return the value of the statement # @abstract + # @protected #*/ sub evaluate { ! my ($this) = @_; ! $this -> { m_executed } = 1; ! } ! ! ! #/** ! # Sets the value of this statement. ! # @protected ! #*/ ! sub setValue { ! my ($this, $value) = @_; ! $this -> { m_value } = $value; ! } ! ! #/** ! # Returns the value of the statement, without executing it ! # If the statement has not been executed upon call of this function, ! # it will execute the statement. ! # @public ! # @final ! #*/ ! sub value { ! my ($this) = @_; ! unless ( $this -> { m_executed }) { ! $this -> evaluate(); ! } ! $this -> { m_value }; } |