Class ::xotcl::package (public)
::nx::Class ::xotcl::package
- Testcases:
- No testcase defined.
Source code: :property provide :property {version 1.0} :property {autoexport {}} :property {export {}} :public object method create {name args} { set nq [namespace qualifiers $name] if {$nq ne "" && ![namespace exists $nq]} {Object create $nq} next } :public object method extend {name args} { :require $name $name configure {*}$args } :public object method contains script { if {[info exists :provide]} { package provide [set :provide] [set :version] } else { package provide [::xotcl::self] [set :version] } namespace eval [::xotcl::self] {namespace import ::xotcl::*} #namespace eval [::xotcl::self] $script #::nsf::directdispatch [::xotcl::self] -frame method ::apply [list {} $script [::xotcl::self]] ::apply [list {} $script [::xotcl::self]] foreach e [set :export] { set nq [namespace qualifiers $e] if {$nq ne ""} { namespace eval [::xotcl::self]::$nq [list namespace export [namespace tail $e]] } else { namespace eval [::xotcl::self] [list namespace export $e] } } foreach e [set :autoexport] { namespace eval :: [list namespace import [::xotcl::self]::$e] } } :public object method unknown args { #puts stderr "unknown: package $args" [set :packagecmd] {*}$args } :public object method verbose value { set :verbose $value } :public object method present args { if {$::tcl_version<8.3} { switch -exact -- [lindex $args 0] { -exact {set pkg [lindex $args 1]} default {set pkg [lindex $args 0]} } if {[info exists :loaded($pkg)]} { return ${:loaded}($pkg) } else { error "not found" } } else { [set :packagecmd] present {*}$args } } :public object method import {{-into ::} pkg} { :require $pkg namespace eval $into [subst -nocommands { #puts stderr "*** package import ${pkg}::* into [namespace current]" namespace import ${pkg}::* }] # import subclasses if any foreach e [$pkg export] { set nq [namespace qualifiers $e] if {$nq ne ""} { namespace eval $into$nq [list namespace import ${pkg}::$e] } } } :public object method require args { #puts "XOTCL package require $args, current=[namespace current]" set prevComponent ${:component} if {[catch {set v [package present {*}$args]} msg]} { #puts stderr "we have to load $msg" switch -exact -- [lindex $args 0] { -exact {set pkg [lindex $args 1]} default {set pkg [lindex $args 0]} } set :component $pkg lappend :uses($prevComponent) ${:component} set v [::uplevel \#1 [set :packagecmd] require $args] if {$v ne "" && ${:verbose}} { set path [lindex [::package ifneeded $pkg $v] 1] puts "... $pkg $v loaded from '$path'" set :loaded($pkg) $v ;# loaded stuff needed for Tcl 8.0 } } set :component $prevComponent return $v } set :component . set :verbose 0 set :packagecmd ::packageXQL Not present: Generic, PostgreSQL, Oracle