Skip to content

Commit

Permalink
implement [namespace current]
Browse files Browse the repository at this point in the history
(cribbed from splitNamespace in partcl, xlated to nqp)
  • Loading branch information
coke committed Aug 17, 2010
1 parent 07d7ad5 commit 3ade1a0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
53 changes: 51 additions & 2 deletions src/Partcl/commands/namespace.pm
Expand Up @@ -104,8 +104,8 @@ my sub code(*@args) {
'';
}

my sub current(*@args) {
'';
my sub current() {
return '::' ~ getNamespace(:depth(2)).join('::') ;
}

my sub delete(*@args) {
Expand Down Expand Up @@ -178,4 +178,53 @@ my sub which(*@args) {
'';
}

### XXX this code from partcl for when old splitNS was called with a string.
## my @list := $name.split(/':' ':'+/);

## my $I0 := +@list;
## if $I0 != 0 && @list[0] == '' {
## @list.shift();
## return @list;
## }

## Depth is the number of frames to skip when checking for current
## namespace.

my sub getNamespace(int :$depth = 0) {

my @list := pir::new('TclList');
my $looper := 1;

my @temp;
while $looper {
$depth++;
## Needed for the multipart keys.
@temp := Q:PIR {
$P0 = find_lex '$depth'
$I0 = $P0
$P1 = getinterp
%r = $P1['sub'; $I0]
};
@temp := @temp.get_namespace().get_name();
## XXX in partcl, we'd check $S0 to _tcl, to know to skip this depth,
## and loop one more time.
## my $S0 := $temp[0];
$looper := 0;
}

my $assert := @temp.pop();
error("ASSERT not rooted in ::tcl namespace")
if $assert ne "tcl";
# The first element is always going to be "::tcl", but we pretend that's
# the root.

my $pos := +@temp;
while $pos > 0 {
$pos--;
@list.unshift( @temp[$pos] );
}

return @list;
}

# vim: expandtab shiftwidth=4 ft=perl6:
2 changes: 1 addition & 1 deletion t/cmd_namespace.t
Expand Up @@ -110,7 +110,7 @@ eval_is {namespace current foo} \
{wrong # args: should be "namespace current"} \
{namespace current: too many args}

is [namespace current] :: {namespace current: global} {TODO NQPRX}
is [namespace current] :: {namespace current: global}
is [namespace eval foo {namespace current}] ::foo {namespace current: ::foo} {TODO NQPRX}


Expand Down

0 comments on commit 3ade1a0

Please sign in to comment.