10 # Anonymous subroutines:
11 '+' => sub {new Oscalar $ {$_[0]}+$_[1]},
12 '-' => sub {new Oscalar
13 $_[2]? $_[1]-${$_[0]} : ${$_[0]}-$_[1]},
14 '<=>' => sub {new Oscalar
15 $_[2]? $_[1]-${$_[0]} : ${$_[0]}-$_[1]},
16 'cmp' => sub {new Oscalar
17 $_[2]? ($_[1] cmp ${$_[0]}) : (${$_[0]} cmp $_[1])},
18 '*' => sub {new Oscalar ${$_[0]}*$_[1]},
19 '/' => sub {new Oscalar
20 $_[2]? $_[1]/${$_[0]} :
22 '%' => sub {new Oscalar
23 $_[2]? $_[1]%${$_[0]} : ${$_[0]}%$_[1]},
24 '**' => sub {new Oscalar
25 $_[2]? $_[1]**${$_[0]} : ${$_[0]}-$_[1]},
29 0+ numify) # Order of arguments unsignificant
37 sub stringify { "${$_[0]}" }
38 sub numify { 0 + "${$_[0]}" } # Not needed, additional overhead
39 # comparing to direct compilation based on
46 print "1..",&last,"\n";
54 print "not ok $test: '$_[0]' ne '$_[1]'\n";
60 print "not ok $test\n";
65 $a = new Oscalar "087";
68 # All test numbers in comments are off by 1.
69 # So much for hard-wiring them in :-) To fix this:
73 test ($b eq "087"); # 3
74 test (ref $a eq "Oscalar"); # 4
76 test ($a eq "087"); # 6
80 test (ref $c eq "Oscalar"); # 7
81 test (!($c eq $a)); # 8
82 test ($c eq "94"); # 9
86 test (ref $a eq "Oscalar"); # 10
90 test (ref $b eq "Oscalar"); # 11
91 test ( $a eq "087"); # 12
92 test ( $b eq "88"); # 13
93 test (ref $a eq "Oscalar"); # 14
98 test (ref $c eq "Oscalar"); # 15
99 test ( $a eq "087"); # 16
100 test ( $c eq "1"); # 17
101 test (ref $a eq "Oscalar"); # 18
106 test (ref $b eq "Oscalar"); # 19
107 test ( $a eq "087"); # 20
108 test ( $b eq "88"); # 21
109 test (ref $a eq "Oscalar"); # 22
111 eval q[ package Oscalar; use overload ('++' => sub { $ {$_[0]}++;$_[0] } ) ];
115 test (ref $a eq "Oscalar"); # 23
119 test (ref $b eq "Oscalar"); # 24
120 test ( $a eq "087"); # 25
121 test ( $b eq "88"); # 26
122 test (ref $a eq "Oscalar"); # 27
125 $dummy=bless \$dummy; # Now cache of method should be reloaded
131 test (ref $b eq "Oscalar"); # 28
132 test ( $a eq "087"); # 29
133 test ( $b eq "88"); # 30
134 test (ref $a eq "Oscalar"); # 31
136 undef $b; # Destroying updates tables too...
138 eval q[package Oscalar; use overload ('++' => sub { $ {$_[0]} += 2; $_[0] } ) ];
142 test (ref $a eq "Oscalar"); # 32
146 test (ref $b eq "Oscalar"); # 33
147 test ( $a eq "087"); # 34
148 test ( $b eq "88"); # 35
149 test (ref $a eq "Oscalar"); # 36
152 $dummy=bless \$dummy; # Now cache of method should be reloaded
157 test (ref $b eq "Oscalar"); # 37
158 test ( $a eq "087"); # 38
159 test ( $b eq "90"); # 39
160 test (ref $a eq "Oscalar"); # 40
165 test (ref $b eq "Oscalar"); # 41
166 test ( $a eq "087"); # 42
167 test ( $b eq "89"); # 43
168 test (ref $a eq "Oscalar"); # 44
173 eval q[ package Oscalar; use overload ('=' => sub {$main::copies++;
175 local $new=$ {$_[0]};
180 test (ref $b eq "Oscalar"); # 46
181 test ( $a eq "087"); # 47
182 test ( $b eq "087"); # 48
183 test (ref $a eq "Oscalar"); # 49
187 test (ref $b eq "Oscalar"); # 50
188 test ( $a eq "087"); # 51
189 test ( $b eq "89"); # 52
190 test (ref $a eq "Oscalar"); # 53
191 test ($copies == 0); # 54
195 test (ref $b eq "Oscalar"); # 55
196 test ( $a eq "087"); # 56
197 test ( $b eq "90"); # 57
198 test (ref $a eq "Oscalar"); # 58
199 test ($copies == 0); # 59
204 test (ref $b eq "Oscalar"); # 60
205 test ( $a eq "087"); # 61
206 test ( $b eq "88"); # 62
207 test (ref $a eq "Oscalar"); # 63
208 test ($copies == 0); # 64
213 test (ref $b eq "Oscalar") || print ref $b,"=ref(b)\n"; # 65
214 test ( $a eq "087"); # 66
215 test ( $b eq "89"); # 67
216 test (ref $a eq "Oscalar"); # 68
217 test ($copies == 1); # 69
219 eval q[package Oscalar; use overload ('+=' => sub {$ {$_[0]} += 3*$_[1];
221 $c=new Oscalar; # Cause rehash
226 test (ref $b eq "Oscalar"); # 70
227 test ( $a eq "087"); # 71
228 test ( $b eq "90"); # 72
229 test (ref $a eq "Oscalar"); # 73
230 test ($copies == 2); # 74
234 test (ref $b eq "Oscalar"); # 75
235 test ( $b eq "360"); # 76
236 test ($copies == 2); # 77
239 test (ref $b eq "Oscalar"); # 78
240 test ( $b eq "-360"); # 79
241 test ($copies == 2); # 80
245 test (ref $b eq "Oscalar"); # 81
246 test ( $b eq "360"); # 82
247 test ($copies == 2); # 83
251 test (ref $b eq "Oscalar"); # 84
252 test ( $b eq "360"); # 85
253 test ($copies == 2); # 86
255 eval q[package Oscalar;
256 use overload ('x' => sub {new Oscalar ( $_[2] ? "_.$_[1]._" x $ {$_[0]}
257 : "_.${$_[0]}._" x $_[1])}) ];
261 test ($a eq "_.yy.__.yy.__.yy._"); # 87
263 eval q[package Oscalar;
264 use overload ('.' => sub {new Oscalar ( $_[2] ?
265 "_.$_[1].__.$ {$_[0]}._"
266 : "_.$ {$_[0]}.__.$_[1]._")}) ];
270 test ("b${a}c" eq "_._.b.__.xx._.__.c._"); # 88
272 # Check inheritance of overloading;
278 $aI = new OscalarI "$a";
279 test (ref $aI eq "OscalarI"); # 89
280 test ("$aI" eq "xx"); # 90
281 test ($aI eq "xx"); # 91
282 test ("b${aI}c" eq "_._.b.__.xx._.__.c._"); # 92
284 # Here we test blessing to a package updates hash
286 eval "package Oscalar; no overload '.'";
288 test ("b${a}" eq "_.b.__.xx._"); # 93
291 test ("b${a}c" eq "bxxc"); # 94
293 test ("b${a}c" eq "bxxc"); # 95
295 # Negative overloading:
298 test($@ =~ /no method found/); # 96
303 sub { *{"Oscalar::$AUTOLOAD"} = sub {"_!_" . shift() . "_!_"} ;
304 goto &{"Oscalar::$AUTOLOAD"}};
306 eval "package Oscalar; sub comple; use overload '~' => 'comple'";
308 $na = eval { ~$a }; # Hash was not updated
309 test($@ =~ /no method found/); # 97
313 $na = eval { ~$a }; # Hash updated
314 warn "`$na', $@" if $@;
316 test($na eq '_!_xx_!_'); # 99
320 $na = eval { ~$aI }; # Hash was not updated
321 test($@ =~ /no method found/); # 100
329 test($na eq '_!_xx_!_'); # 102
331 eval "package Oscalar; sub rshft; use overload '>>' => 'rshft'";
333 $na = eval { $aI >> 1 }; # Hash was not updated
334 test($@ =~ /no method found/); # 103
340 $na = eval { $aI >> 1 };
344 test($na eq '_!_xx_!_'); # 105
346 # warn overload::Method($a, '0+'), "\n";
347 test (overload::Method($a, '0+') eq \&Oscalar::numify); # 106
348 test (overload::Method($aI,'0+') eq \&Oscalar::numify); # 107
349 test (overload::Overloaded($aI)); # 108
350 test (!overload::Overloaded('overload')); # 109
352 test (! defined overload::Method($aI, '<<')); # 110
353 test (! defined overload::Method($a, '<')); # 111
355 test (overload::StrVal($aI) =~ /^OscalarI=SCALAR\(0x[\da-fA-F]+\)$/); # 112
356 test (overload::StrVal(\$aI) eq "@{[\$aI]}"); # 113
358 # Check overloading by methods (specified deep in the ISA tree).
362 sub Oscalar::lshft {"_<<_" . shift() . "_<<_"}
363 eval "package OscalarI; use overload '<<' => 'lshft', '|' => 'lshft'";
368 bless $aII, 'OscalarII';
369 bless \$fake, 'OscalarI'; # update the hash
370 test(($aI | 3) eq '_<<_xx_<<_'); # 114
372 test(($aII << 3) eq '_<<_087_<<_'); # 115
375 BEGIN { $int = 7; overload::constant 'integer' => sub {$int++; shift}; }
379 test($out, 1024); # 117
384 BEGIN { $q = $qr = 7;
385 overload::constant 'q' => sub {$q++; push @q, shift, ($_[1] || 'none'); shift},
386 'qr' => sub {$qr++; push @qr, shift, ($_[1] || 'none'); shift}; }
389 $out2 = "a\a$foo,\,";
393 test($out, 'foo'); # 118
394 test($out, $foo); # 119
395 test($out1, 'f\'o\\o'); # 120
396 test($out1, $foo1); # 121
397 test($out2, "a\afoo,\,"); # 122
398 test("@q", "foo q f'o\\\\o q a\\a qq ,\\, qq"); # 123
400 test("@qr", "b\\b qq .\\. qq"); # 125
404 $_ = '!<b>!foo!<-.>!';
405 BEGIN { overload::constant 'q' => sub {push @q1, shift, ($_[1] || 'none'); "_<" . (shift) . ">_"},
406 'qr' => sub {push @qr1, shift, ($_[1] || 'none'); "!<" . (shift) . ">!"}; }
409 $out2 = "a\a$foo,\,";
419 s'first part'second part';
420 s/yet another/tail here/;
424 test($out, '_<foo>_'); # 117
425 test($out1, '_<f\'o\\o>_'); # 128
426 test($out2, "_<a\a>_foo_<,\,>_"); # 129
427 test("@q1", "foo q f'o\\\\o q a\\a qq ,\\, qq oups
429 q second part q tail here s A-Z tr a-z tr"); # 130
430 test("@qr1", "b\\b qq .\\. qq try it q first part q yet another qq"); # 131
436 test($c, "bareword"); # 135
439 package symbolic; # Primitive symbolic calculator
440 use overload nomethod => \&wrap, '""' => \&str, '0+' => \&num,
441 '=' => \&cpy, '++' => \&inc, '--' => \&dec;
443 sub new { shift; bless ['n', @_] }
446 bless [@$self], ref $self;
448 sub inc { $_[0] = bless ['++', $_[0], 1]; }
449 sub dec { $_[0] = bless ['--', $_[0], 1]; }
451 my ($obj, $other, $inv, $meth) = @_;
452 if ($meth eq '++' or $meth eq '--') {
453 @$obj = ($meth, (bless [@$obj]), 1); # Avoid circular reference
456 ($obj, $other) = ($other, $obj) if $inv;
457 bless [$meth, $obj, $other];
460 my ($meth, $a, $b) = @{+shift};
461 $a = 'u' unless defined $a;
468 my %subr = ( 'n' => sub {$_[0]} );
469 foreach my $op (split " ", $overload::ops{with_assign}) {
470 $subr{$op} = $subr{"$op="} = eval "sub {shift() $op shift()}";
472 my @bins = qw(binary 3way_comparison num_comparison str_comparison);
473 foreach my $op (split " ", "@overload::ops{ @bins }") {
474 $subr{$op} = eval "sub {shift() $op shift()}";
476 foreach my $op (split " ", "@overload::ops{qw(unary func)}") {
477 $subr{$op} = eval "sub {$op shift()}";
479 $subr{'++'} = $subr{'+'};
480 $subr{'--'} = $subr{'-'};
483 my ($meth, $a, $b) = @{+shift};
484 my $subr = $subr{$meth}
485 or die "Do not know how to ($meth) in symbolic";
486 $a = $a->num if ref $a eq __PACKAGE__;
487 $b = $b->num if ref $b eq __PACKAGE__;
490 sub TIESCALAR { my $pack = shift; $pack->new(@_) }
492 sub nop { } # Around a bug
493 sub vars { my $p = shift; tie($_, $p), $_->nop foreach @_; }
502 my $foo = new symbolic 11;
504 test( (sprintf "%d", $foo), '12');
505 test( (sprintf "%d", $baz), '11');
508 test( (sprintf "%d", $foo), '13');
509 test( (sprintf "%d", $bar), '12');
510 test( (sprintf "%d", $baz), '13');
513 test( (sprintf "%d", $foo), '14');
514 test( (sprintf "%d", $bar), '12');
515 test( (sprintf "%d", $baz), '14');
516 test( (sprintf "%d", $ban), '13');
519 test( (sprintf "%d", $foo), '15');
520 test( (sprintf "%d", $baz), '14');
521 test( "$foo", '[++ [+= [++ [++ [n 11] 1] 1] 1] 1]');
525 my $iter = new symbolic 2;
526 my $side = new symbolic 1;
530 $cnt = $cnt - 1; # The "simple" way
531 $side = (sqrt(1 + $side**2) - 1)/$side;
533 my $pi = $side*(2**($iter+2));
534 test "$side", '[/ [- [sqrt [+ 1 [** [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]] 2]]] 1] [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]]]';
535 test( (sprintf "%f", $pi), '3.182598');
539 my $iter = new symbolic 2;
540 my $side = new symbolic 1;
544 $side = (sqrt(1 + $side**2) - 1)/$side;
546 my $pi = $side*(2**($iter+2));
547 test "$side", '[/ [- [sqrt [+ 1 [** [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]] 2]]] 1] [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]]]';
548 test( (sprintf "%f", $pi), '3.182598');
553 symbolic->vars($a, $b);
554 my $c = sqrt($a**2 + $b**2);
556 test( (sprintf "%d", $c), '5');
558 test( (sprintf "%d", $c), '13');
562 package symbolic1; # Primitive symbolic calculator
564 use overload nomethod => \&wrap, '""' => \&str, '0+' => \&num, '=' => \&cpy;
566 sub new { shift; bless ['n', @_] }
569 bless [@$self], ref $self;
572 my ($obj, $other, $inv, $meth) = @_;
573 if ($meth eq '++' or $meth eq '--') {
574 @$obj = ($meth, (bless [@$obj]), 1); # Avoid circular reference
577 ($obj, $other) = ($other, $obj) if $inv;
578 bless [$meth, $obj, $other];
581 my ($meth, $a, $b) = @{+shift};
582 $a = 'u' unless defined $a;
589 my %subr = ( 'n' => sub {$_[0]} );
590 foreach my $op (split " ", $overload::ops{with_assign}) {
591 $subr{$op} = $subr{"$op="} = eval "sub {shift() $op shift()}";
593 my @bins = qw(binary 3way_comparison num_comparison str_comparison);
594 foreach my $op (split " ", "@overload::ops{ @bins }") {
595 $subr{$op} = eval "sub {shift() $op shift()}";
597 foreach my $op (split " ", "@overload::ops{qw(unary func)}") {
598 $subr{$op} = eval "sub {$op shift()}";
600 $subr{'++'} = $subr{'+'};
601 $subr{'--'} = $subr{'-'};
604 my ($meth, $a, $b) = @{+shift};
605 my $subr = $subr{$meth}
606 or die "Do not know how to ($meth) in symbolic";
607 $a = $a->num if ref $a eq __PACKAGE__;
608 $b = $b->num if ref $b eq __PACKAGE__;
611 sub TIESCALAR { my $pack = shift; $pack->new(@_) }
613 sub nop { } # Around a bug
614 sub vars { my $p = shift; tie($_, $p), $_->nop foreach @_; }
623 my $foo = new symbolic1 11;
625 test( (sprintf "%d", $foo), '12');
626 test( (sprintf "%d", $baz), '11');
629 test( (sprintf "%d", $foo), '13');
630 test( (sprintf "%d", $bar), '12');
631 test( (sprintf "%d", $baz), '13');
634 test( (sprintf "%d", $foo), '14');
635 test( (sprintf "%d", $bar), '12');
636 test( (sprintf "%d", $baz), '14');
637 test( (sprintf "%d", $ban), '13');
640 test( (sprintf "%d", $foo), '15');
641 test( (sprintf "%d", $baz), '14');
642 test( "$foo", '[++ [+= [++ [++ [n 11] 1] 1] 1] 1]');
646 my $iter = new symbolic1 2;
647 my $side = new symbolic1 1;
651 $cnt = $cnt - 1; # The "simple" way
652 $side = (sqrt(1 + $side**2) - 1)/$side;
654 my $pi = $side*(2**($iter+2));
655 test "$side", '[/ [- [sqrt [+ 1 [** [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]] 2]]] 1] [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]]]';
656 test( (sprintf "%f", $pi), '3.182598');
660 my $iter = new symbolic1 2;
661 my $side = new symbolic1 1;
665 $side = (sqrt(1 + $side**2) - 1)/$side;
667 my $pi = $side*(2**($iter+2));
668 test "$side", '[/ [- [sqrt [+ 1 [** [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]] 2]]] 1] [/ [- [sqrt [+ 1 [** [n 1] 2]]] 1] [n 1]]]';
669 test( (sprintf "%f", $pi), '3.182598');
674 symbolic1->vars($a, $b);
675 my $c = sqrt($a**2 + $b**2);
677 test( (sprintf "%d", $c), '5');
679 test( (sprintf "%d", $c), '13');
683 package two_face; # Scalars with separate string and
685 sub new { my $p = shift; bless [@_], $p }
686 use overload '""' => \&str, '0+' => \&num, fallback => 1;
692 my $seven = new two_face ("vii", 7);
693 test( (sprintf "seven=$seven, seven=%d, eight=%d", $seven, $seven+1),
694 'seven=vii, seven=7, eight=8');
695 test( scalar ($seven =~ /i/), '1')
700 use overload 'cmp' => \∁
701 sub new { my ($p, $v) = @_; bless \$v, $p }
702 sub comp { my ($x,$y) = @_; ($$x * 3 % 10) <=> ($$y * 3 % 10) or $$x cmp $$y }
705 my @arr = map sorting->new($_), 0..12;
706 my @sorted1 = sort @arr;
707 my @sorted2 = map $$_, @sorted1;
708 test "@sorted2", '0 10 7 4 1 11 8 5 12 2 9 6 3';
712 use overload '<>' => \&iter;
713 sub new { my ($p, $v) = @_; bless \$v, $p }
714 sub iter { my ($x) = @_; return undef if $$x < 0; return $$x--; }
717 # XXX iterator overload not intended to work with CORE::GLOBAL?
718 if (defined &CORE::GLOBAL::glob) {
724 my $iter = iterator->new(5);
727 $acc .= " $out" while $out = <${iter}>;
728 test $acc, ' 5 4 3 2 1 0'; # 175
729 $iter = iterator->new(5);
730 test scalar <${iter}>, '5'; # 176
732 $acc .= " $out" while $out = <$iter>;
733 test $acc, ' 4 3 2 1 0'; # 177
737 use overload '%{}' => \&hderef, '&{}' => \&cderef,
738 '*{}' => \&gderef, '${}' => \&sderef, '@{}' => \&aderef;
739 sub new { my ($p, $v) = @_; bless \$v, $p }
741 my ($self, $key) = (shift, shift);
742 my $class = ref $self;
743 bless $self, 'deref::dummy'; # Disable overloading of %{}
744 my $out = $self->{$key};
745 bless $self, $class; # Restore overloading
748 sub hderef {shift->deref('h')}
749 sub aderef {shift->deref('a')}
750 sub cderef {shift->deref('c')}
751 sub gderef {shift->deref('g')}
752 sub sderef {shift->deref('s')}
755 my $deref = bless { h => { foo => 5 , fake => 23 },
756 c => sub {return shift() + 34},
762 my @cont = sort %$deref;
763 if ("\t" eq "\011") { # ascii
764 test "@cont", '23 5 fake foo'; # 178
766 else { # ebcdic alpha-numeric sort order
767 test "@cont", 'fake foo 23 5'; # 178
769 my @keys = sort keys %$deref;
770 test "@keys", 'fake foo'; # 179
771 my @val = sort values %$deref;
772 test "@val", '23 5'; # 180
773 test $deref->{foo}, 5; # 181
774 test defined $deref->{bar}, ''; # 182
777 push @keys, $key while $key = each %$deref;
779 test "@keys", 'fake foo'; # 183
780 test exists $deref->{bar}, ''; # 184
781 test exists $deref->{foo}, 1; # 185
783 test $deref->(5), 39; # 186
784 test &$deref(6), 40; # 187
785 sub xxx_goto { goto &$deref }
786 test xxx_goto(7), 41; # 188
787 my $srt = bless { c => sub {$b <=> $a}
790 my @sorted = sort srt 11, 2, 5, 1, 22;
791 test "@sorted", '22 11 5 2 1'; # 189
793 test $$deref, 123; # 190
795 @sorted = sort $srt 11, 2, 5, 1, 22;
796 test "@sorted", '22 11 5 2 1'; # 191
798 test "@$deref", '11 12 13'; # 192
799 test $#$deref, '2'; # 193
802 test $deref->[2], '13'; # 195
806 test $deref->[$l], '12'; # 197
807 # Repeated dereference
808 my $double = bless { h => $deref,
810 test $double->{foo}, 5; # 198
815 use overload '%{}' => \&gethash, '@{}' => sub { ${shift()} };
823 tie %h, ref $self, $self;
827 sub TIEHASH { my $p = shift; bless \ shift, $p }
830 $fields{$_} = $i++ foreach qw{zero one two three};
832 my $self = ${shift()};
833 my $key = $fields{shift()};
834 defined $key or die "Out of band access";
835 $$self->[$key] = shift;
838 my $self = ${shift()};
839 my $key = $fields{shift()};
840 defined $key or die "Out of band access";
845 my $bar = new two_refs 3,4,5,6;
847 test $bar->{two}, 11; # 199
849 test $bar->[3], 13; # 200
856 $bar = new two_refs_o 3,4,5,6;
858 test $bar->{two}, 11; # 201
860 test $bar->[3], 13; # 202
864 use overload '%{}' => sub { ${shift()}->[1] },
865 '@{}' => sub { ${shift()}->[0] };
871 bless \ [$a, \%h], $p;
876 tie %h, ref $self, $self;
880 sub TIEHASH { my $p = shift; bless \ shift, $p }
883 $fields{$_} = $i++ foreach qw{zero one two three};
886 my $key = $fields{shift()};
887 defined $key or die "Out of band access";
892 my $key = $fields{shift()};
893 defined $key or die "Out of band access";
898 $bar = new two_refs_o 3,4,5,6;
900 test $bar->{two}, 11; # 203
902 test $bar->[3], 13; # 204
906 @ISA = ('two_refs1');
909 $bar = new two_refs1_o 3,4,5,6;
911 test $bar->{two}, 11; # 205
913 test $bar->[3], 13; # 206
917 use overload bool => sub { ${+shift} };
921 { my $bbbb = 0; $aaa = bless \$bbbb, B }
926 test 'ok', 'ok'; # 208
928 test 'is not', 'ok'; # 208
931 # check that overload isn't done twice by join
934 use overload '""' => sub { $c++ };
935 my $x = join '', bless([]), 'pq', bless([]);
936 main::test $x, '0pq1'; # 209
939 # Test module-specific warning
941 # check the Odd number of arguments for overload::constant warning
943 local $SIG{__WARN__} = sub {$a = $_[0]} ;
944 $x = eval ' overload::constant "integer" ; ' ;
945 test($a eq "") ; # 210
946 use warnings 'overload' ;
947 $x = eval ' overload::constant "integer" ; ' ;
948 test($a =~ /^Odd number of arguments for overload::constant at/) ; # 211
952 # check the `$_[0]' is not an overloadable type warning
954 local $SIG{__WARN__} = sub {$a = $_[0]} ;
955 $x = eval ' overload::constant "fred" => sub {} ; ' ;
956 test($a eq "") ; # 212
957 use warnings 'overload' ;
958 $x = eval ' overload::constant "fred" => sub {} ; ' ;
959 test($a =~ /^`fred' is not an overloadable type at/); # 213
963 # check the `$_[1]' is not a code reference warning
965 local $SIG{__WARN__} = sub {$a = $_[0]} ;
966 $x = eval ' overload::constant "integer" => 1; ' ;
967 test($a eq "") ; # 214
968 use warnings 'overload' ;
969 $x = eval ' overload::constant "integer" => 1; ' ;
970 test($a =~ /^`1' is not a code reference at/); # 215
976 use overload '""' => sub { 3+shift->[0] },
977 '0+' => sub { 10+shift->[0] },
978 'int' => sub { 100+shift->[0] };
979 sub new {my $p = shift; bless [shift], $p}
982 use overload '""' => sub { 5+shift->[0] },
983 '0+' => sub { 30+shift->[0] },
984 'int' => sub { 'ov_int1'->new(1000+shift->[0]) };
985 sub new {my $p = shift; bless [shift], $p}
988 use overload '""' => sub { 2+shift->[0] },
989 '0+' => sub { 9+shift->[0] };
990 sub new {my $p = shift; bless [shift], $p}
994 my $x = new noov_int 11;
996 main::test("$int_x" eq 20); # 216
999 main::test("$int_x" eq 131); # 217
1000 $x = new ov_int2 51;
1002 main::test("$int_x" eq 1054); # 218
1005 # make sure that we don't inifinitely recurse
1009 use overload '""' => sub { shift },
1010 '0+' => sub { shift },
1011 'bool' => sub { shift },
1014 main::test("$x" =~ /Recurse=ARRAY/); # 219
1015 main::test($x); # 220
1016 main::test($x+0 =~ /Recurse=ARRAY/); # 221
1019 # BugID 20010422.003
1023 'bool' => sub { return !$_[0]->is_zero() || undef; }
1029 return $self->{var} == 0;
1036 $self->{var} = shift;
1044 my $r = Foo->new(8);
1047 test(($r || 0) == 0); # 222