Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tony-o
committed
Oct 30, 2015
0 parents
commit 000c086
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: perl | ||
perl: | ||
- '5.20' | ||
env: | ||
- BACKEND=moar | ||
- BACKEND=jvm | ||
matrix: | ||
allow_failures: | ||
- env: BACKEND=jvm | ||
fast_finish: true | ||
sudo: false | ||
before_install: | ||
- git clone https://github.com/rakudo/rakudo.git $HOME/rakudo | ||
- cd $HOME/rakudo | ||
- 'if [[ $BACKEND == "moar" ]]; then perl Configure.pl --gen-moar --gen-nqp --backends=$BACKEND; fi' | ||
- 'if [[ $BACKEND == "jvm" ]]; then perl Configure.pl --gen-nqp --backends=$BACKEND; fi' | ||
- make install | ||
- export PATH=$HOME/rakudo/install/bin:$PATH | ||
- cd $TRAVIS_BUILD_DIR | ||
install: | ||
# need at least 1 statement in 'install' | ||
- perl6 -v | ||
script: | ||
- prove -v -e 'perl6 -Ilib' t/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name" : "Module::Does", | ||
"version" : "0.1", | ||
"description" : "role for finding loaded modules in global scope that 'does' some role or class, useful for modules that want to support hot swapping modules with minimal end user code", | ||
"depends" : [], | ||
"provides" : { | ||
"Module::Does": "lib/Module/Does.pm6" | ||
}, | ||
"source-url" : "git://github.com/tony-o/perl6-module-does.git" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
sub findglob($type, @start = GLOBAL::.values.Slip){ | ||
my @found; | ||
for @start -> $t { | ||
try @found.append: |@(findglob($type, $t.WHO.values.Slip)); | ||
try @found.append: $t if $t ~~ ::($type); | ||
} | ||
return @found; | ||
} | ||
|
||
role Module::Does[*@types] { | ||
has %!base-types; | ||
submethod BUILD(*%_){ | ||
for @types { | ||
$_ = $_.^name unless $_ ~~ Pair || $_ ~~ Str; | ||
given $_ { | ||
when * ~~ Pair { | ||
%!base-types{$_.key} = findglob($_.key); | ||
%!base-types{$_.key} = findglob($_.value) unless | ||
%!base-types{$_.key}.elems > 0; | ||
} | ||
when Str { | ||
%!base-types{$_} = findglob($_); | ||
} | ||
default { | ||
die "Unknown type passed $_"; | ||
} | ||
} | ||
} | ||
callsame; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env perl6 | ||
|
||
use lib 'lib'; | ||
use Module::Does; | ||
use Test; | ||
|
||
plan 5; | ||
|
||
class C { has $.x = 5; } | ||
role D { has $.y = 42; } | ||
class F does D { }; | ||
|
||
class A does Module::Does[@(C, D => 'E', Module::Does)] { | ||
has $.xx = 24; | ||
method base-types { %!base-types; } | ||
} | ||
|
||
my A $a .=new; | ||
|
||
ok C ~~ any(@($a.base-types<C>)); | ||
ok F ~~ any(@($a.base-types<D>)); | ||
ok D ~~ any(@($a.base-types<D>)); | ||
ok Module::Does ~~ any(@($a.base-types<Module::Does>)); | ||
ok A ~~ any(@($a.base-types<Module::Does>)); | ||
|
||
# vi:syntax=perl6 |