| | 122 | |
| | 123 | { |
| | 124 | class Incrementor { |
| | 125 | has $.value; |
| | 126 | |
| | 127 | method succ() { |
| | 128 | $.value += 42; |
| | 129 | } |
| | 130 | } |
| | 131 | |
| | 132 | my $o = Incrementor.new( value => 0 ); |
| | 133 | $o++; |
| | 134 | is $o.value, 42, 'Overriding succ catches postfix increment'; |
| | 135 | ++$o; |
| | 136 | is $o.value, 84, 'Overriding succ catches prefix increment'; |
| | 137 | } |
| | 138 | |
| | 139 | { |
| | 140 | class Decrementor { |
| | 141 | has $.value; |
| | 142 | |
| | 143 | method pred() { |
| | 144 | $.value -= 42; |
| | 145 | } |
| | 146 | } |
| | 147 | |
| | 148 | my $o = Decrementor.new( value => 100 ); |
| | 149 | $o--; |
| | 150 | is $o.value, 58, 'Overriding pred catches postfix decrement'; |
| | 151 | --$o; |
| | 152 | is $o.value, 16, 'Overriding pred catches prefix decrement'; |
| | 153 | } |