Beta Shell
v2.0 ยท web2.us.cloudlogin.co
[FM]
[CMD]
[PHP]
[DB]
[INFO]
[SEC]
File Manager
~
/
usr
/
share
/
doc
/
perl-Moose
/
t
/
recipes
Upload
21 items
Name
Size
Perms
Modified
Actions
[ .. / .. ]
basics_bankaccount_methodmodifiersandsubclassing.t
3.71 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_binarytree_attributefeatures.t
3.83 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_company_subtypes.t
9.54 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_datetime_extendingnonmooseparent.t
1.16 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_document_augmentandinner.t
1.45 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_genome_overloadingsubtypesandcoercion.t
5.2 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_http_subtypesandcoercion.t
3.24 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
basics_point_attributesandsubclassing.t
5.35 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
extending_debugging_baseclassrole.t
755 B
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
extending_mooseish_moosesugar.t
983 B
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
legacy_debugging_baseclassreplacement.t
953 B
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
legacy_labeled_attributemetaclass.t
1.52 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
meta_globref_instancemetaclass.t
3.23 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
meta_labeled_attributetrait.t
1.43 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
meta_privateorpublic_methodmetaclass.t
1.93 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
meta_table_metaclasstrait.t
798 B
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
roles_applicationtoinstance.t
1.73 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
roles_comparable_codereuse.t
5.16 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
roles_restartable_advancedcomposition.t
2 KB
-rw-r--r--
2019-10-21 09:36:33
Edit
Del
Editing: roles_applicationtoinstance.t
(1.73 KB)
Path: /usr/share/doc/perl-Moose/t/recipes/roles_applicationtoinstance.t
Back
#!/usr/bin/perl -w use strict; use Test::More 'no_plan'; use Test::Fatal; $| = 1; # =begin testing SETUP { # Not in the recipe, but needed for writing tests. package Employee; use Moose; has 'name' => ( is => 'ro', isa => 'Str', required => 1, ); has 'work' => ( is => 'rw', isa => 'Str', predicate => 'has_work', ); } # =begin testing SETUP { package MyApp::Role::Job::Manager; use List::Util qw( first ); use Moose::Role; has 'employees' => ( is => 'rw', isa => 'ArrayRef[Employee]', ); sub assign_work { my $self = shift; my $work = shift; my $employee = first { !$_->has_work } @{ $self->employees }; die 'All my employees have work to do!' unless $employee; $employee->work($work); } package main; my $lisa = Employee->new( name => 'Lisa' ); MyApp::Role::Job::Manager->meta->apply($lisa); my $homer = Employee->new( name => 'Homer' ); my $bart = Employee->new( name => 'Bart' ); my $marge = Employee->new( name => 'Marge' ); $lisa->employees( [ $homer, $bart, $marge ] ); $lisa->assign_work('mow the lawn'); } # =begin testing { { my $lisa = Employee->new( name => 'Lisa' ); MyApp::Role::Job::Manager->meta->apply($lisa); my $homer = Employee->new( name => 'Homer' ); my $bart = Employee->new( name => 'Bart' ); my $marge = Employee->new( name => 'Marge' ); $lisa->employees( [ $homer, $bart, $marge ] ); $lisa->assign_work('mow the lawn'); ok( $lisa->does('MyApp::Role::Job::Manager'), 'lisa now does the manager role' ); is( $homer->work, 'mow the lawn', 'homer was assigned a task by lisa' ); } } 1;