Skip to content

Commit

Permalink
add simplistic [namespace children]; no tests pass yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Aug 21, 2010
1 parent 7d7afd0 commit 983f476
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/Partcl/commands/namespace.pm
Expand Up @@ -96,8 +96,40 @@ our sub dispatch_command(*@args) {
&subcommand(|@args);
}

my sub children(*@args) {
'';
my sub children($namespace = pir::new('TclString'), $pattern = '*') {

my @ns := $namespace.split(/\:\:+/);
if +@ns && @ns[+@ns-1] eq '' {
@ns.pop();
}
if +@ns && @ns[0] eq '' {
@ns.shift();
}
my $prefix := "::" ~ @ns.join("::");
$prefix := $prefix ~ "::" unless $prefix eq "::";

my $regex := StringGlob::Compiler.compile($pattern);

my $ns := pir::get_hll_namespace__p();
for @ns -> $level {
$ns := $ns{$level};
if pir::typeof($ns) ne 'NameSpace' {
error("namespace \"$namespace\" not found in ::");
}
}

my @result := pir::new('TclList');
for $ns -> $key {
my $element := $ns{$key};
if (pir::typeof($element) eq 'NameSpace') {
if ?Regex::Cursor.parse($element, :rule($regex), :c(0)) {
@result.push($prefix ~ $element);
}
}
}


return @result;
}

my sub code(*@args) {
Expand Down

0 comments on commit 983f476

Please sign in to comment.