You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by mx...@apache.org on 2011/03/28 16:30:34 UTC

svn commit: r1086253 - in /tcl/rivet/branches/rivet-namespace/rivet: init.tcl rivet-tcl/incr0.tcl rivet-tcl/tclIndex

Author: mxmanghi
Date: Mon Mar 28 14:30:34 2011
New Revision: 1086253

URL: http://svn.apache.org/viewvc?rev=1086253&view=rev
Log:
added export of commands implemented in tcl. init.tcl now imports the rivet namespace

Modified:
    tcl/rivet/branches/rivet-namespace/rivet/init.tcl
    tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/incr0.tcl
    tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/tclIndex

Modified: tcl/rivet/branches/rivet-namespace/rivet/init.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/rivet-namespace/rivet/init.tcl?rev=1086253&r1=1086252&r2=1086253&view=diff
==============================================================================
--- tcl/rivet/branches/rivet-namespace/rivet/init.tcl (original)
+++ tcl/rivet/branches/rivet-namespace/rivet/init.tcl Mon Mar 28 14:30:34 2011
@@ -17,6 +17,51 @@ package provide RivetTcl 2.1
 namespace eval ::Rivet {
 
     ###
+    ## export_tcl_commands --
+    ## this is temporary hack to export names of Tcl commands in rivet-tcl/.
+    ## This function will be removed in future versions of Rivet and it's
+    ## meant to provide a basic way to guarantee compatibility with older
+    ## versions of Rivet (see code in ::Rivet::init)
+    ##
+
+    proc export_tcl_commands {tclpath} {
+
+        # we collect the commands in rivet-tcl by reading the tclIndex
+        # file and then we extract the command list from auto_index
+
+        namespace eval ::rivet_temp { }
+        set ::rivet_temp::tclpath $tclpath
+
+        namespace eval ::rivet_temp {
+            variable auto_index
+            array set auto_index {}
+
+            # the auto_index in ${tclpath}/tclIndex is loaded
+            
+            set dir $tclpath
+            source [file join $tclpath tclIndex]
+        }
+        
+        set command_list [namespace eval ::rivet_temp {array names auto_index}]
+
+        # commands in 'command_list' are prefixed with ::rivet, so we have to
+        # remove it to build an export list 
+        
+        set export_list {}
+        foreach c $command_list {
+            if {[regexp {::rivet::(.*)} $c m cmd]} {
+                lappend export_list $cmd
+                namespace eval ::rivet [list namespace export $cmd]
+            }
+        }
+
+        # we won't left anything behind
+        namespace delete ::rivet_temp
+
+        return $export_list
+    }
+
+    ###
     ## This routine gets called each time a new request comes in.
     ## It sets up the request namespace and creates a global command
     ## to replace the default global.  This ensures that when a user
@@ -72,6 +117,16 @@ namespace eval ::Rivet {
         set tclpath [file join [file dirname [info script]] rivet-tcl]
         set auto_path [linsert $auto_path 0 $tclpath]
 
+        ## As we moved the commands ensemble to ::rivet namespace we
+        ## we want to guarantee the commands are still accessible
+        ## at global level by putting them on the export list.
+        ## Importing the ::rivet namespace is deprecated and we should
+        ## make it clear that this will be removed in the future
+
+        ## we keep in ::rivet::export_list a list of importable commands
+
+        set ::rivet::export_list [export_tcl_commands $tclpath]
+
         ## Add the packages directory to the auto_path.
         ## If we have a packages$tcl_version directory
         ## (IE: packages8.3, packages8.4) append that as well.
@@ -106,8 +161,13 @@ namespace eval ::Rivet {
 ## in Rivet < 2.1.0, before the move into the ::Rivet namespace, 
 ## we alias this command only in the global namespace
 
-interp alias {} incr0 {} incr
+interp alias {} ::rivet::incr0 {} incr
 
 ## Initialize Rivet.
 ::Rivet::init
 
+## And now we come to the import of the whole ::rivet namespace. 
+## Some commands (namely lassign) replace the native lassign command
+## so we have to  use the -force switch
+
+namespace import -force ::rivet::*

Modified: tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/incr0.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/incr0.tcl?rev=1086253&r1=1086252&r2=1086253&view=diff
==============================================================================
--- tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/incr0.tcl (original)
+++ tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/incr0.tcl Mon Mar 28 14:30:34 2011
@@ -11,8 +11,12 @@
 ##
 ###
 
-proc incr0 {varName {num 1}} {
-    upvar 1 $varName var
-    if {![info exists var]} { set var 0 }
-    return [incr var $num]
+namespace eval ::rivet {
+
+    proc incr0 {varName {num 1}} {
+        upvar 1 $varName var
+        if {![info exists var]} { set var 0 }
+        return [incr var $num]
+    }
+
 }

Modified: tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/tclIndex
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/tclIndex?rev=1086253&r1=1086252&r2=1086253&view=diff
==============================================================================
--- tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/tclIndex (original)
+++ tcl/rivet/branches/rivet-namespace/rivet/rivet-tcl/tclIndex Mon Mar 28 14:30:34 2011
@@ -6,18 +6,18 @@
 # element name is the name of a command and the value is
 # a script that loads the command.
 
-set auto_index(::rivet::html) [list source [file join $dir html.tcl]]
-set auto_index(incr0) [list source [file join $dir incr0.tcl]]
-set auto_index(::rivet::lassign) [list source [file join $dir lassign.tcl]]
 set auto_index(::rivet::random) [list source [file join $dir random.tcl]]
+set auto_index(::rivet::import_keyvalue_pairs) [list source [file join $dir import_keyvalue_pairs.tcl]]
+set auto_index(::rivet::read_file) [list source [file join $dir read_file.tcl]]
 set auto_index(::rivet::rivet_command_document) [list source [file join $dir rivet_command_document.tcl]]
+set auto_index(::rivet::html) [list source [file join $dir html.tcl]]
+set auto_index(::rivet::lassign) [list source [file join $dir lassign.tcl]]
+set auto_index(::rivet::incr0) [list source [file join $dir incr0.tcl]]
+set auto_index(::rivet::load_cookies) [list source [file join $dir load_cookies.tcl]]
+set auto_index(::rivet::parray) [list source [file join $dir parray.tcl]]
+set auto_index(::rivet::lmatch) [list source [file join $dir lmatch.tcl]]
+set auto_index(::rivet::lempty) [list source [file join $dir lempty.tcl]]
 set auto_index(::rivet::load_response) [list source [file join $dir load_response.tcl]]
 set auto_index(::rivet::debug) [list source [file join $dir debug.tcl]]
-set auto_index(::rivet::lempty) [list source [file join $dir lempty.tcl]]
-set auto_index(::rivet::lmatch) [list source [file join $dir lmatch.tcl]]
-set auto_index(::rivet::read_file) [list source [file join $dir read_file.tcl]]
-set auto_index(::rivet::import_keyvalue_pairs) [list source [file join $dir import_keyvalue_pairs.tcl]]
-set auto_index(::rivet::parray) [list source [file join $dir parray.tcl]]
 set auto_index(::rivet::wrap) [list source [file join $dir wrap.tcl]]
 set auto_index(::rivet::wrapline) [list source [file join $dir wrap.tcl]]
-set auto_index(::rivet::load_cookies) [list source [file join $dir load_cookies.tcl]]



---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-cvs-help@tcl.apache.org