::xox
Class Package

Heritage:
::xotcl::Object
  |
  +--::xox::NotGarbageCollectable
Associated Test:
::xox::test::TestPackage

Class Package
superclass ::xox::NotGarbageCollectable,
Package represents information about tcl packages. Currently
 this is just used to add comments about a package in xodocument.
 In the future Package could provide methods for building
 pkgIndex.tcl files from the directory where the package lives.
 It could also provide methods for package requiring all subpackages.

 To add a package description to the generated add the following
 to your superpackage file:

 xox.tcl:

 Package xox
 xox # Package description {

     xox is an extension of XOTcl.  xox adds instprocs, and instmixins to ::xotcl::Class and ::xotcl::Object.
 }

 This creates an object that represents the xox package.  Use
 the "namespace tail" of the namespace for the object name.  
 xodocuement looks for this object at the location:

 ${namespace}::[ namespace tail $namespace ]

 For ::xox this is ::xox::xox

 You should also the same namespace and package name, except
 leave the :: off of the beginning of the package name.

 Thus ::xox is the namespace name, xox is the package name.
Variables
NameDefault ValueClassComment
executables    ::xox::Package
 A list of paths to executable scripts in this package
location    ::xox::Package
 Path to this package.  This is useful for modules that contain several packages
packageFile    ::xox::Package
 The name of the file containing the package
packagePath    ::xox::Package
 The absolute path to the directory containing the package
subPackages    ::xox::Package
 If a module contains other packages this is used to denote what other packages are available.
 
Methods
NameComment
export {namespace}   Exports all the procedures defined on this package to a target namespace
findPackages {}  
forgetAll {}  
import {}   Imports all the procedures defined on this package to the current namespace
init {}   Saves the location of the package in packageFile and packagePath
load {}   Forces a package to package require all of its sub-packages and calls package provide for this package
loadAll {}   Forces a package to package require all of its sub-packages and calls package provide for this package
packageName {}  
reload {}   Reload the package
   
Methods from ::xotcl::Object
#, ., ?, ?code, ?methods, ?object, abstract, copy, coverageFilter, defaultmethod, extractConfigureArg, filterappend, garbageCollect, get#, getClean#, hasclass, init, methodTag, mixinappend, move, profileFilter, self, setParameterDefaults, shell, tclcmd, traceFilter,
 
Instproc Detail

export

Description:
 Exports all the procedures defined on this package to a target namespace.
Arguments:
Code:
  ::xox::Package instproc export {namespace}  {
   

        namespace eval $namespace {

            foreach proc [ my info procs ] {

                proc $proc { args } "
                    uplevel [ self ]::$proc \$args
                "
            }
        }
    
}

findPackages

Description:
 
Code:
  ::xox::Package instproc findPackages {}  {
   

        catch { package require notapackage }
    
}

forgetAll

Description:
 
Code:
  ::xox::Package instproc forgetAll {}  {
   

        set packageName [ my packageName ]

        set subs [ ::xox::removeIfNot { string match "${packageName}*" $name } name [ package names ] ]

        foreach sub $subs {

            #my debug "forget $sub"

            package forget $sub
        }
    
}

import

Description:
 Imports all the procedures defined on this package to the current namespace.
Code:
  ::xox::Package instproc import {}  {
   

        namespace eval [ uplevel namespace current ] {

            foreach proc [ my info procs ] {

                proc $proc { args } "
                    uplevel [ self ]::$proc \$args
                "
            }
        }
    
}

init

Description:
 Saves the location of the package in packageFile and packagePath
Overrides:
init in ::xotcl::Object
Code:
  ::xox::Package instproc init {}  {
   

        my packageFile [ file tail [ info script ] ]
        my packagePath [ file dirname [ info script ] ]
    
}

load

Description:
 Forces a package to package require all of its
 sub-packages and calls package provide for this
 package. Package load does not load the test sub-package.
 This is loaded by Package loadAll.
Code:
  ::xox::Package instproc load {}  {
   

        #my debug "Loading [ self ]"

        set packageName [ my packageName ]

        package provide $packageName 1.0
        namespace eval ::${packageName} {
            namespace import -force ::xotcl::*
        }

        foreach name [ package names ] {

           if { [ string first "${packageName}::" $name ] == 0 } {

               if { [ string first "${packageName}::test" $name ] == 0 } {
                   continue
               }

               set qualifiers [ namespace qualifiers $name ]

                namespace eval ::${qualifiers} {
                    namespace import -force ::xotcl::*
                }


               #my debug "package require $name"

               package require $name
           }
        }
    
}

loadAll

Description:
 Forces a package to package require all of its
 sub-packages and calls package provide for this
 package. Package loadAll does load the test sub-package.
Code:
  ::xox::Package instproc loadAll {}  {
   

        #my debug "Loading [ self ]"

        set packageName [ my packageName ]

        ##puts "Loading: $packageName"

        package provide $packageName 1.0
        #puts "Provide: $packageName 1.0"
        namespace eval ::${packageName} {
            namespace import -force ::xotcl::*
        }
        #puts "Namespace: ::${packageName}"

        namespace eval ::${packageName}::test {
            namespace import -force ::xotcl::*
        }
        #puts "Namespace: ::${packageName}::test"

        foreach name [ package names ] {

           if { [ string first "${packageName}::" $name ] == 0 } {

               #my debug "package require $name"

               package require $name
           }
        }
    
}

packageName

Description:
 
Code:
  ::xox::Package instproc packageName {}  {
   

        return [ string range [ self ] 2 end ]
    
}

reload

Description:
 Reload the package.
Code:
  ::xox::Package instproc reload {}  {
   

        my debug "Forgetting [ self ]"

        my forgetAll

        my debug "Finding [ self ]"

        my findPackages

        my debug "Loading [ self ]"


        #Package require is causes some serious
        #seg faults. Lets try load
        #package require [ my packageName ]

        #Load still causes seg faults
        my load
    
}