Skip to content

Instantly share code, notes, and snippets.

@ChoHag
Created July 28, 2015 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChoHag/3645dd1638a73b32430d to your computer and use it in GitHub Desktop.
Save ChoHag/3645dd1638a73b32430d to your computer and use it in GitHub Desktop.
SAD.pm:
use SAD::Special;
class SAD {
has $!nothing;
}
SAD/Special.pm:
role SAD::Special {
has Bool $.special_thing = True;
method apply_handles($att: Mu $pkg) {
my $accessor = $att.name.substr(2);
say "Apply to $accessor.";
$!special_thing = False if $accessor ~~ 'other-thing';
}
}
multi trait_mod:<is>(Attribute $a, :$special!) is export {
$a does SAD::Special;
}
SAD/Thing.pm:
use SAD;
use SAD::Special;
class SAD::Thing {
has $.thing is special;
has $.other-thing is special;
}
@LLFourn
Copy link

LLFourn commented Jul 28, 2015

This will re-export the trait mod so you only have to use SAD in Thing.pm

use SAD::Special;

sub EXPORT (|) {
    {
        '&trait_mod:<is>' => &trait_mod:<is>
    }
}

class SAD {
    has $!nothing;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment