Skip to content

Commit

Permalink
Added .children(:all) for nodes and schemas
Browse files Browse the repository at this point in the history
It returns all the nodes as a single list
  • Loading branch information
LLFourn committed Mar 5, 2016
1 parent fc9dfbd commit ba52054
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "OO::Schema",
"perl" : "6.*",
"version" : "0.2.0",
"version" : "0.2.1",
"description" : "Declare class relationships in a single module",
"authors" : ["Lloyd Fournier"],
"provides" : {
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ usually called on the schema.
``` perl6
Userland.children # Windows, POSIX
POSIX.children # BSD, GNU
GNU.children(:all) # Debian, Ubuntu, RHEL, Fedora,CentOS
```

returns the node's child nodes.
Returns the node's direct child nodes. if `:all` is passed, returns
all descendants.

## Traits

Expand Down
6 changes: 3 additions & 3 deletions lib/OO/Schema.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ my role SchemaNode {
}
}

submethod children {
self.^children;
submethod children(:$all){
|self.^children, |(self.^children».children(:all) if $all);
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ my role Schema {
submethod resolve($test) {
self.^children.map(*.resolve($test)).first(* !=== Any);
}
submethod children { self.^children }
submethod children(:$all) { flat self.^children,(|self.^children».children(:all) if $all) };
}


Expand Down
33 changes: 33 additions & 0 deletions t/04-children.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use Test;
use lib $?FILE.IO.parent.child("lib01").Str;

plan 4;

{
use OS::Userland;
ok Userland.children ~~ set(Windows,POSIX),".children";
ok Userland.children(:all) ~~ set(
Windows,
XP,
WindowsServer,
POSIX,
BSD,
FreeBSD,
OpenBSD,
OSX,
GNU,
Debian,
Ubuntu,
RHEL,
Fedora,
CentOS,
),".children(:all)";
ok GNU.children ~~ set(Debian,RHEL),"GNU.children";
ok GNU.children(:all) ~~ set(
Debian,
Ubuntu,
RHEL,
Fedora,
CentOS,
),"GNU.children(:all)";
}

0 comments on commit ba52054

Please sign in to comment.