1 # Testing magical scalars (using tied scalar)
2 # Note that XSUBs do not handle magical scalars automatically.
10 use Class::Load qw( is_class_loaded load_class );
19 Foo->meta->add_attribute('bar' =>
24 Foo->meta->add_attribute('baz' =>
28 Foo->meta->make_immutable();
32 tie my $foo, 'Tie::StdScalar', Foo->new(bar => 100, baz => 200);
34 is $foo->get_bar, 100, 'reader with tied self';
35 is $foo->baz, 200, 'accessor/r with tied self';
40 is $foo->get_bar, 300, 'writer with tied self';
41 is $foo->baz, 400, 'accessor/w with tied self';
47 tie my $value, 'Tie::StdScalar', 42;
49 $foo->set_bar($value);
52 is $foo->get_bar, 42, 'reader/writer with tied value';
53 is $foo->baz, 42, 'accessor with tied value';
57 my $x = tie my $value, 'Tie::StdScalar', 'Class::MOP';
59 is( exception { load_class($value) }, undef, 'load_class(tied scalar)' );
62 $x->STORE('Class::MOP'); # reset
65 ok is_class_loaded($value);
66 }, undef, 'is_class_loaded(tied scalar)' );
69 $x->STORE(\&Class::MOP::get_code_info); # reset
72 is_deeply [Class::MOP::get_code_info($value)], [qw(Class::MOP get_code_info)], 'get_code_info(tied scalar)';