diff options
Diffstat (limited to 't/lib')
-rw-r--r-- | t/lib/AtomicMethod.pm | 27 | ||||
-rw-r--r-- | t/lib/AtomicMethod/Role/Method.pm | 15 | ||||
-rw-r--r-- | t/lib/Command.pm | 31 | ||||
-rw-r--r-- | t/lib/Command/Role/Class.pm | 26 | ||||
-rw-r--r-- | t/lib/Command/Role/Method.pm | 4 | ||||
-rw-r--r-- | t/lib/FileAttributes.pm | 29 |
6 files changed, 132 insertions, 0 deletions
diff --git a/t/lib/AtomicMethod.pm b/t/lib/AtomicMethod.pm new file mode 100644 index 0000000..652159a --- /dev/null +++ b/t/lib/AtomicMethod.pm @@ -0,0 +1,27 @@ +package AtomicMethod; +use MooseX::Exporter::Easy; + +sub _atomic_method_meta { + my ($meta) = @_; + Moose::Meta::Class->create_anon_class( + superclasses => [$meta->method_metaclass], + roles => ['AtomicMethod::Role::Method'], + cache => 1, + )->name; +} + +with_meta atomic_method => sub { + my ($meta, $name, $code) = @_; + $meta->add_method( + $name => _atomic_method_meta($meta)->wrap( + $code, + name => $name, + package_name => $meta->name, + associated_metaclass => $meta + ), + ); +}; + +export; + +1; diff --git a/t/lib/AtomicMethod/Role/Method.pm b/t/lib/AtomicMethod/Role/Method.pm new file mode 100644 index 0000000..e11f506 --- /dev/null +++ b/t/lib/AtomicMethod/Role/Method.pm @@ -0,0 +1,15 @@ +package AtomicMethod::Role::Method; +use Moose::Role; + +around wrap => sub { + my ($orig, $self, $body, @args) = @_; + my $new_body = sub { + warn "locking...\n"; + my @ret = $body->(@_); # XXX: context + warn "unlocking...\n"; + return @ret; + }; + $self->$orig($new_body, @args); +}; + +1; diff --git a/t/lib/Command.pm b/t/lib/Command.pm new file mode 100644 index 0000000..b39b8b5 --- /dev/null +++ b/t/lib/Command.pm @@ -0,0 +1,31 @@ +package Command; +use MooseX::Exporter::Easy; + +class_metaroles { + class => ['Command::Role::Class'], +}; + +sub _command_method_meta { + my ($meta) = @_; + Moose::Meta::Class->create_anon_class( + superclasses => [$meta->method_metaclass], + roles => ['Command::Role::Method'], + cache => 1, + )->name; +} + +with_meta command => sub { + my ($meta, $name, $code) = @_; + $meta->add_method( + $name => _command_method_meta($meta)->wrap( + $code, + name => $name, + package_name => $meta->name, + associated_metaclass => $meta + ), + ); +}; + +export; + +1; diff --git a/t/lib/Command/Role/Class.pm b/t/lib/Command/Role/Class.pm new file mode 100644 index 0000000..78b48db --- /dev/null +++ b/t/lib/Command/Role/Class.pm @@ -0,0 +1,26 @@ +package Command::Role::Class; +use Moose::Role; + +sub get_all_commands { + my ($self) = @_; + grep { Moose::Util::does_role($_, 'Command::Role::Method') } + $self->get_all_methods; +} + +sub has_command { + my ($self, $name) = @_; + my $method = $self->find_method_by_name($name); + return unless $method; + return Moose::Util::does_role($method, 'Command::Role::Method'); +} + +sub get_command { + my ($self, $name) = @_; + my $method = $self->find_method_by_name($name); + return unless $method; + return Moose::Util::does_role($method, 'Command::Role::Method') + ? $method + : (); +} + +1; diff --git a/t/lib/Command/Role/Method.pm b/t/lib/Command/Role/Method.pm new file mode 100644 index 0000000..29152ac --- /dev/null +++ b/t/lib/Command/Role/Method.pm @@ -0,0 +1,4 @@ +package Command::Role::Method; +use Moose::Role; + +1; diff --git a/t/lib/FileAttributes.pm b/t/lib/FileAttributes.pm new file mode 100644 index 0000000..04e6f2e --- /dev/null +++ b/t/lib/FileAttributes.pm @@ -0,0 +1,29 @@ +package FileAttributes; +use MooseX::Exporter::Easy; +use MooseX::Types::Path::Class qw(File Dir); + +with_meta has_file => sub { + my ($meta, $name, %options) = @_; + $meta->add_attribute( + $name, + is => 'ro', + isa => File, + coerce => 1, + %options, + ); +}; + +with_meta has_dir => sub { + my ($meta, $name, %options) = @_; + $meta->add_attribute( + $name, + is => 'ro', + isa => Dir, + coerce => 1, + %options, + ); +}; + +export; + +1; |