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: basics_binarytree_attributefeatures.t
(3.83 KB)
Path: /usr/share/doc/perl-Moose/t/recipes/basics_binarytree_attributefeatures.t
Back
#!/usr/bin/perl -w use strict; use Test::More 'no_plan'; use Test::Fatal; $| = 1; # =begin testing SETUP { package BinaryTree; use Moose; has 'node' => ( is => 'rw', isa => 'Any' ); has 'parent' => ( is => 'rw', isa => 'BinaryTree', predicate => 'has_parent', weak_ref => 1, ); has 'left' => ( is => 'rw', isa => 'BinaryTree', predicate => 'has_left', lazy => 1, default => sub { BinaryTree->new( parent => $_[0] ) }, trigger => \&_set_parent_for_child ); has 'right' => ( is => 'rw', isa => 'BinaryTree', predicate => 'has_right', lazy => 1, default => sub { BinaryTree->new( parent => $_[0] ) }, trigger => \&_set_parent_for_child ); sub _set_parent_for_child { my ( $self, $child ) = @_; confess "You cannot insert a tree which already has a parent" if $child->has_parent; $child->parent($self); } } # =begin testing { use Scalar::Util 'isweak'; my $root = BinaryTree->new(node => 'root'); isa_ok($root, 'BinaryTree'); is($root->node, 'root', '... got the right node value'); ok(!$root->has_left, '... no left node yet'); ok(!$root->has_right, '... no right node yet'); ok(!$root->has_parent, '... no parent for root node'); # make a left node my $left = $root->left; isa_ok($left, 'BinaryTree'); is($root->left, $left, '... got the same node (and it is $left)'); ok($root->has_left, '... we have a left node now'); ok($left->has_parent, '... lefts has a parent'); is($left->parent, $root, '... lefts parent is the root'); ok(isweak($left->{parent}), '... parent is a weakened ref'); ok(!$left->has_left, '... $left no left node yet'); ok(!$left->has_right, '... $left no right node yet'); is($left->node, undef, '... left has got no node value'); is( exception { $left->node('left'); }, undef, '... assign to lefts node' ); is($left->node, 'left', '... left now has a node value'); # make a right node ok(!$root->has_right, '... still no right node yet'); is($root->right->node, undef, '... right has got no node value'); ok($root->has_right, '... now we have a right node'); my $right = $root->right; isa_ok($right, 'BinaryTree'); is( exception { $right->node('right'); }, undef, '... assign to rights node' ); is($right->node, 'right', '... left now has a node value'); is($root->right, $right, '... got the same node (and it is $right)'); ok($root->has_right, '... we have a right node now'); ok($right->has_parent, '... rights has a parent'); is($right->parent, $root, '... rights parent is the root'); ok(isweak($right->{parent}), '... parent is a weakened ref'); # make a left node of the left node my $left_left = $left->left; isa_ok($left_left, 'BinaryTree'); ok($left_left->has_parent, '... left does have a parent'); is($left_left->parent, $left, '... got a parent node (and it is $left)'); ok($left->has_left, '... we have a left node now'); is($left->left, $left_left, '... got a left node (and it is $left_left)'); ok(isweak($left_left->{parent}), '... parent is a weakened ref'); # make a right node of the left node my $left_right = BinaryTree->new; isa_ok($left_right, 'BinaryTree'); is( exception { $left->right($left_right); }, undef, '... assign to rights node' ); ok($left_right->has_parent, '... left does have a parent'); is($left_right->parent, $left, '... got a parent node (and it is $left)'); ok($left->has_right, '... we have a left node now'); is($left->right, $left_right, '... got a left node (and it is $left_left)'); ok(isweak($left_right->{parent}), '... parent is a weakened ref'); # and check the error isnt( exception { $left_right->right($left_left); }, undef, '... cannot assign a node which already has a parent' ); } 1;