From 42385a5a09bee71148e745ccbfe0a8d5286255f8 Mon Sep 17 00:00:00 2001 From: doy Date: Sun, 26 Apr 2009 19:25:37 -0500 Subject: more renamespacing --- lib/Bot/Games.pm | 2 +- lib/Bot/Games/Game.pm | 4 +-- lib/Bot/Games/Meta/Role/Attribute/Command.pm | 45 ---------------------------- lib/Bot/Games/Meta/Role/Class/Command.pm | 23 -------------- lib/Bot/Games/Meta/Role/Method/Command.pm | 24 --------------- lib/Bot/Games/OO/Game.pm | 8 ++--- lib/Bot/Games/Trait/Attribute/Command.pm | 45 ++++++++++++++++++++++++++++ lib/Bot/Games/Trait/Class/Command.pm | 23 ++++++++++++++ lib/Bot/Games/Trait/Method/Command.pm | 24 +++++++++++++++ 9 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 lib/Bot/Games/Meta/Role/Attribute/Command.pm delete mode 100644 lib/Bot/Games/Meta/Role/Class/Command.pm delete mode 100644 lib/Bot/Games/Meta/Role/Method/Command.pm create mode 100644 lib/Bot/Games/Trait/Attribute/Command.pm create mode 100644 lib/Bot/Games/Trait/Class/Command.pm create mode 100644 lib/Bot/Games/Trait/Method/Command.pm diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm index 7bdcd79..fb8df7c 100644 --- a/lib/Bot/Games.pm +++ b/lib/Bot/Games.pm @@ -172,7 +172,7 @@ sub _get_command { return $method_meta if blessed($method_meta) && $method_meta->meta->can('does_role') - && $method_meta->meta->does_role('Bot::Games::Meta::Role::Method::Command'); + && $method_meta->meta->does_role('Bot::Games::Trait::Method::Command'); } __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Bot/Games/Game.pm b/lib/Bot/Games/Game.pm index 55a1547..ceeda9d 100644 --- a/lib/Bot/Games/Game.pm +++ b/lib/Bot/Games/Game.pm @@ -15,7 +15,7 @@ has help => ( # just use that instead. has players => ( metaclass => 'Collection::Array', - traits => [qw/Bot::Games::Meta::Role::Attribute::Command/], + traits => [qw/Bot::Games::Trait::Attribute::Command/], is => 'ro', isa => 'ArrayRef[Str]', auto_deref => 1, @@ -69,7 +69,7 @@ command cmdlist => sub { for my $method ($self->meta->get_all_methods) { push @commands, $method->name if $method->meta->can('does_role') - && $method->meta->does_role('Bot::Games::Meta::Role::Command'); + && $method->meta->does_role('Bot::Games::Trait::Method::Command'); } return join ' ', sort map { '-' . $_ } @commands; }, needs_init => 0; diff --git a/lib/Bot/Games/Meta/Role/Attribute/Command.pm b/lib/Bot/Games/Meta/Role/Attribute/Command.pm deleted file mode 100644 index bf3ea50..0000000 --- a/lib/Bot/Games/Meta/Role/Attribute/Command.pm +++ /dev/null @@ -1,45 +0,0 @@ -package Bot::Games::Meta::Role::Attribute::Command; -use Moose::Role; - -has command => ( - is => 'rw', - isa => 'Bool', - default => 0, -); - -has needs_init => ( - is => 'rw', - isa => 'Bool', - default => 1, -); - -before _process_options => sub { - my $self = shift; - my ($name, $options) = @_; - warn "needs_init is useless for attributes without command" - if exists($options->{needs_init}) && !$options->{command}; -}; - -around accessor_metaclass => sub { - my $orig = shift; - my $self = shift; - my $metaclass = $self->$orig(@_); - return $metaclass unless $self->command; - return Moose::Meta::Class->create_anon_class( - superclasses => [$metaclass], - roles => ['Bot::Games::Meta::Role::Method::Command'], - cache => 1, - )->name; -}; - -after install_accessors => sub { - my $self = shift; - return unless $self->command; - my $method_meta = $self->get_read_method_ref; - $method_meta->pass_args(0); - $method_meta->needs_init($self->needs_init); -}; - -no Moose::Role; - -1; diff --git a/lib/Bot/Games/Meta/Role/Class/Command.pm b/lib/Bot/Games/Meta/Role/Class/Command.pm deleted file mode 100644 index 9e8d647..0000000 --- a/lib/Bot/Games/Meta/Role/Class/Command.pm +++ /dev/null @@ -1,23 +0,0 @@ -package Bot::Games::Meta::Role::Class::Command; -use Moose::Role; - -after ((map { "add_${_}_method_modifier" } qw/before after around/) => sub { - my $self = shift; - my $name = shift; - - my $method_meta = $self->get_method($name); - my $orig_method_meta = $method_meta->get_original_method; - return unless $orig_method_meta->meta->can('does_role') - && $orig_method_meta->meta->does_role('Bot::Games::Meta::Role::Method::Command'); - my $pass_args = $orig_method_meta->pass_args; - my $method_metaclass = Moose::Meta::Class->create_anon_class( - superclasses => [blessed $method_meta], - roles => ['Bot::Games::Meta::Role::Method::Command'], - cache => 1, - ); - $method_metaclass->rebless_instance($method_meta, pass_args => $pass_args); -}); - -no Moose::Role; - -1; diff --git a/lib/Bot/Games/Meta/Role/Method/Command.pm b/lib/Bot/Games/Meta/Role/Method/Command.pm deleted file mode 100644 index 36e496f..0000000 --- a/lib/Bot/Games/Meta/Role/Method/Command.pm +++ /dev/null @@ -1,24 +0,0 @@ -package Bot::Games::Meta::Role::Method::Command; -use Moose::Role; - -has pass_args => ( - is => 'rw', - isa => 'Bool', - default => 1, -); - -has needs_init => ( - is => 'rw', - isa => 'Bool', - default => 1, -); - -around execute => sub { - my $orig = shift; - my $self = shift; - return $self->pass_args ? $self->$orig(@_) : $self->$orig($_[0]); -}; - -no Moose::Role; - -1; diff --git a/lib/Bot/Games/OO/Game.pm b/lib/Bot/Games/OO/Game.pm index 938af7c..b260477 100644 --- a/lib/Bot/Games/OO/Game.pm +++ b/lib/Bot/Games/OO/Game.pm @@ -8,7 +8,7 @@ sub command { my $superclass = Moose::blessed($method_meta) || 'Moose::Meta::Method'; my $method_metaclass = Moose::Meta::Class->create_anon_class( superclasses => [$superclass], - roles => ['Bot::Games::Meta::Role::Method::Command'], + roles => ['Bot::Games::Trait::Method::Command'], cache => 1, ); if ($method_meta) { @@ -22,7 +22,7 @@ sub command { ); $class->meta->add_method($name, $method_meta); } - for my $attr (Bot::Games::Meta::Role::Method::Command->meta->get_attribute_list) { + for my $attr (Bot::Games::Trait::Method::Command->meta->get_attribute_list) { $method_meta->$attr($args{$attr}) if exists $args{$attr}; } } @@ -40,9 +40,9 @@ sub init_meta { for_class => $options{for_class}, attribute_metaclass_roles => - ['Bot::Games::Meta::Role::Attribute::Command'], + ['Bot::Games::Trait::Attribute::Command'], metaclass_roles => - ['Bot::Games::Meta::Role::Class::Command'], + ['Bot::Games::Trait::Class::Command'], ); return $options{for_class}->meta; } diff --git a/lib/Bot/Games/Trait/Attribute/Command.pm b/lib/Bot/Games/Trait/Attribute/Command.pm new file mode 100644 index 0000000..9b51b13 --- /dev/null +++ b/lib/Bot/Games/Trait/Attribute/Command.pm @@ -0,0 +1,45 @@ +package Bot::Games::Trait::Attribute::Command; +use Moose::Role; + +has command => ( + is => 'rw', + isa => 'Bool', + default => 0, +); + +has needs_init => ( + is => 'rw', + isa => 'Bool', + default => 1, +); + +before _process_options => sub { + my $self = shift; + my ($name, $options) = @_; + warn "needs_init is useless for attributes without command" + if exists($options->{needs_init}) && !$options->{command}; +}; + +around accessor_metaclass => sub { + my $orig = shift; + my $self = shift; + my $metaclass = $self->$orig(@_); + return $metaclass unless $self->command; + return Moose::Meta::Class->create_anon_class( + superclasses => [$metaclass], + roles => ['Bot::Games::Trait::Method::Command'], + cache => 1, + )->name; +}; + +after install_accessors => sub { + my $self = shift; + return unless $self->command; + my $method_meta = $self->get_read_method_ref; + $method_meta->pass_args(0); + $method_meta->needs_init($self->needs_init); +}; + +no Moose::Role; + +1; diff --git a/lib/Bot/Games/Trait/Class/Command.pm b/lib/Bot/Games/Trait/Class/Command.pm new file mode 100644 index 0000000..3c242ae --- /dev/null +++ b/lib/Bot/Games/Trait/Class/Command.pm @@ -0,0 +1,23 @@ +package Bot::Games::Trait::Class::Command; +use Moose::Role; + +after ((map { "add_${_}_method_modifier" } qw/before after around/) => sub { + my $self = shift; + my $name = shift; + + my $method_meta = $self->get_method($name); + my $orig_method_meta = $method_meta->get_original_method; + return unless $orig_method_meta->meta->can('does_role') + && $orig_method_meta->meta->does_role('Bot::Games::Trait::Method::Command'); + my $pass_args = $orig_method_meta->pass_args; + my $method_metaclass = Moose::Meta::Class->create_anon_class( + superclasses => [blessed $method_meta], + roles => ['Bot::Games::Trait::Method::Command'], + cache => 1, + ); + $method_metaclass->rebless_instance($method_meta, pass_args => $pass_args); +}); + +no Moose::Role; + +1; diff --git a/lib/Bot/Games/Trait/Method/Command.pm b/lib/Bot/Games/Trait/Method/Command.pm new file mode 100644 index 0000000..e00cb43 --- /dev/null +++ b/lib/Bot/Games/Trait/Method/Command.pm @@ -0,0 +1,24 @@ +package Bot::Games::Trait::Method::Command; +use Moose::Role; + +has pass_args => ( + is => 'rw', + isa => 'Bool', + default => 1, +); + +has needs_init => ( + is => 'rw', + isa => 'Bool', + default => 1, +); + +around execute => sub { + my $orig = shift; + my $self = shift; + return $self->pass_args ? $self->$orig(@_) : $self->$orig($_[0]); +}; + +no Moose::Role; + +1; -- cgit v1.2.3-54-g00ecf