2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
19 U(sub { my $h = shift; sub { $f->(U($h)->())->(@_) } })->();
33 sub head { (shift)->_list->[0] }
38 @{$self->_list}[1 .. $#{$self->_list}]
44 join ", " => @{$_[0]->_list};
47 package List::Immutable;
53 sub is_empty { not defined ($_[0]->head) }
60 my ($list, $acc) = @_;
61 return $acc if $list->is_empty;
62 $redo->($list->tail, $acc + 1);
68 my ($self, $function) = @_;
72 my ($list, $func, $acc) = @_;
73 return (ref $list)->new('::' => $acc)
78 [ @{$acc}, $func->($list->head) ]
81 }))->($self, $function, []);
88 with 'List', 'List::Immutable';
89 } '... successfully composed roles together';
95 with 'List::Immutable', 'List';
96 } '... successfully composed roles together';
101 my $coll = My::List1->new;
102 isa_ok($coll, 'My::List1');
104 ok($coll->does('List'), '... $coll does List');
105 ok($coll->does('List::Immutable'), '... $coll does List::Immutable');
107 ok($coll->is_empty, '... we have an empty collection');
108 is($coll->length, 0, '... we have a length of 1 for the collection');
112 my $coll = My::List2->new;
113 isa_ok($coll, 'My::List2');
115 ok($coll->does('List'), '... $coll does List');
116 ok($coll->does('List::Immutable'), '... $coll does List::Immutable');
118 ok($coll->is_empty, '... we have an empty collection');
119 is($coll->length, 0, '... we have a length of 1 for the collection');
123 my $coll = My::List1->new('::' => [ 1 .. 10 ]);
124 isa_ok($coll, 'My::List1');
126 ok($coll->does('List'), '... $coll does List');
127 ok($coll->does('List::Immutable'), '... $coll does List::Immutable');
129 ok(!$coll->is_empty, '... we do not have an empty collection');
130 is($coll->length, 10, '... we have a length of 10 for the collection');
132 is($coll->print, '1, 2, 3, 4, 5, 6, 7, 8, 9, 10', '... got the right printed value');
134 my $coll2 = $coll->apply(sub { $_[0] * $_[0] });
135 isa_ok($coll2, 'My::List1');
137 is($coll->print, '1, 2, 3, 4, 5, 6, 7, 8, 9, 10', '... original is still the same');
138 is($coll2->print, '1, 4, 9, 16, 25, 36, 49, 64, 81, 100', '... new collection is changed');
142 my $coll = My::List2->new('::' => [ 1 .. 10 ]);
143 isa_ok($coll, 'My::List2');
145 ok($coll->does('List'), '... $coll does List');
146 ok($coll->does('List::Immutable'), '... $coll does List::Immutable');
148 ok(!$coll->is_empty, '... we do not have an empty collection');
149 is($coll->length, 10, '... we have a length of 10 for the collection');
151 is($coll->print, '1, 2, 3, 4, 5, 6, 7, 8, 9, 10', '... got the right printed value');
153 my $coll2 = $coll->apply(sub { $_[0] * $_[0] });
154 isa_ok($coll2, 'My::List2');
156 is($coll->print, '1, 2, 3, 4, 5, 6, 7, 8, 9, 10', '... original is still the same');
157 is($coll2->print, '1, 4, 9, 16, 25, 36, 49, 64, 81, 100', '... new collection is changed');