From: Matt S Trout Date: Sun, 8 Apr 2012 19:47:07 +0000 (+0000) Subject: restricted code X-Git-Tag: v1.000_900~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=73cc2ff34b3414c749e6e8f42a919175aa7f08d3;p=gitmo%2FRole-Tiny.git restricted code --- diff --git a/lib/Role/Tiny/Restricted.pm b/lib/Role/Tiny/Restricted.pm new file mode 100644 index 0000000..713e431 --- /dev/null +++ b/lib/Role/Tiny/Restricted.pm @@ -0,0 +1,18 @@ +package Role::Tiny::Restricted; + +use strict; +use warnings FATAL => 'all'; +use base qw(Role::Tiny); + +sub apply_union_of_roles_to_package { + my ($me, $to, @roles) = @_; + my %app = %{$Role::Tiny::APPLIED_TO{$to}||{}}; + delete $app{$to}; + if (%app) { + require Carp; + Carp::confess("with() may not be called more than once for $to"); + } + $me->SUPER::apply_union_of_roles_to_package($to, @roles); +} + +1; diff --git a/lib/Role/Tiny/Restricted/With.pm b/lib/Role/Tiny/Restricted/With.pm new file mode 100644 index 0000000..06c1958 --- /dev/null +++ b/lib/Role/Tiny/Restricted/With.pm @@ -0,0 +1,15 @@ +package Role::Tiny::Restricted::With; + +use strict; +use warnings FATAL => 'all'; +use Role::Tiny::Restricted (); + +use Exporter 'import'; +our @EXPORT = qw( with ); + +sub with { + my $target = caller; + Role::Tiny::Restricted->apply_union_of_roles_to_package($target, @_) +} + +1;