22 my @string_defaults = (
34 for my $default (@int_defaults) {
35 my $copy = $default; # so we can print it out without modifying flags
36 my $attr = Class::MOP::Attribute->new(
37 foo => (default => $default, reader => 'foo'),
39 my $meta = Class::MOP::Class->create_anon_class(
40 attributes => [$attr],
41 methods => {bar => sub { $default }},
44 my $obj = $meta->new_object;
45 for my $meth (qw(foo bar)) {
46 my $val = $obj->$meth;
47 my $b = B::svref_2object(\$val);
48 my $flags = $b->FLAGS;
49 ok($flags & B::SVf_IOK || $flags & B::SVp_IOK, "it's an int ($copy)");
50 ok(!($flags & B::SVf_POK), "not a string ($copy)");
53 $meta->make_immutable;
55 my $immutable_obj = $meta->name->new;
56 for my $meth (qw(foo bar)) {
57 my $val = $immutable_obj->$meth;
58 my $b = B::svref_2object(\$val);
59 my $flags = $b->FLAGS;
60 ok($flags & B::SVf_IOK || $flags & B::SVp_IOK, "it's an int ($copy) (immutable)");
61 ok(!($flags & B::SVf_POK), "not a string ($copy) (immutable)");
65 for my $default (@num_defaults) {
66 my $copy = $default; # so we can print it out without modifying flags
67 my $attr = Class::MOP::Attribute->new(
68 foo => (default => $default, reader => 'foo'),
70 my $meta = Class::MOP::Class->create_anon_class(
71 attributes => [$attr],
72 methods => {bar => sub { $default }},
75 my $obj = $meta->new_object;
76 for my $meth (qw(foo bar)) {
77 my $val = $obj->$meth;
78 my $b = B::svref_2object(\$val);
79 my $flags = $b->FLAGS;
80 ok($flags & B::SVf_NOK || $flags & B::SVp_NOK, "it's a num ($copy)");
81 ok(!($flags & B::SVf_POK), "not a string ($copy)");
84 $meta->make_immutable;
86 my $immutable_obj = $meta->name->new;
87 for my $meth (qw(foo bar)) {
88 my $val = $immutable_obj->$meth;
89 my $b = B::svref_2object(\$val);
90 my $flags = $b->FLAGS;
91 ok($flags & B::SVf_NOK || $flags & B::SVp_NOK, "it's a num ($copy) (immutable)");
92 ok(!($flags & B::SVf_POK), "not a string ($copy) (immutable)");
96 for my $default (@string_defaults) {
97 my $copy = $default; # so we can print it out without modifying flags
98 my $attr = Class::MOP::Attribute->new(
99 foo => (default => $default, reader => 'foo'),
101 my $meta = Class::MOP::Class->create_anon_class(
102 attributes => [$attr],
103 methods => {bar => sub { $default }},
106 my $obj = $meta->new_object;
107 for my $meth (qw(foo bar)) {
108 my $val = $obj->$meth;
109 my $b = B::svref_2object(\$val);
110 my $flags = $b->FLAGS;
111 ok($flags & B::SVf_POK, "it's a string ($copy)");
114 $meta->make_immutable;
116 my $immutable_obj = $meta->name->new;
117 for my $meth (qw(foo bar)) {
118 my $val = $immutable_obj->$meth;
119 my $b = B::svref_2object(\$val);
120 my $flags = $b->FLAGS;
121 ok($flags & B::SVf_POK, "it's a string ($copy) (immutable)");