+
+ tie my $scalar, 'TieScalarCounter', 10;
+ my $fetch = $scalar;
+
+ is tied($scalar)->{fetch}, 1;
+ is tied($scalar)->{store}, 0;
+ is Devel::PPPort::magic_SvIV_nomg($scalar), 10;
+ is tied($scalar)->{fetch}, 1;
+ is tied($scalar)->{store}, 0;
+ is Devel::PPPort::magic_SvUV_nomg($scalar), 10;
+ is tied($scalar)->{fetch}, 1;
+ is tied($scalar)->{store}, 0;
+ is Devel::PPPort::magic_SvNV_nomg($scalar), 10;
+ is tied($scalar)->{fetch}, 1;
+ is tied($scalar)->{store}, 0;
+ is Devel::PPPort::magic_SvPV_nomg_nolen($scalar), 10;
+ is tied($scalar)->{fetch}, 1;
+ is tied($scalar)->{store}, 0;
+ ok Devel::PPPort::magic_SvTRUE_nomg($scalar);
+ is tied($scalar)->{fetch}, 1;
+ is tied($scalar)->{store}, 0;
+
+ my $object = OverloadedObject->new('string', 5.5, 0);
+
+ is Devel::PPPort::magic_SvIV_nomg($object), 5;
+ is Devel::PPPort::magic_SvUV_nomg($object), 5;
+ is Devel::PPPort::magic_SvNV_nomg($object), 5.5;
+ is Devel::PPPort::magic_SvPV_nomg_nolen($object), 'string';
+ ok !Devel::PPPort::magic_SvTRUE_nomg($object);
+
+tie my $negative, 'TieScalarCounter', -1;
+$fetch = $negative;
+
+is tied($negative)->{fetch}, 1;
+is tied($negative)->{store}, 0;
+is Devel::PPPort::magic_SvIV_nomg($negative), -1;
+if (ivers($]) >= ivers("5.6")) {
+ ok !Devel::PPPort::SVf_IVisUV($negative);
+} else {
+ skip 'SVf_IVisUV is unsupported', 1;
+}
+is tied($negative)->{fetch}, 1;
+is tied($negative)->{store}, 0;
+Devel::PPPort::magic_SvUV_nomg($negative);
+if (ivers($]) >= ivers("5.6")) {
+ ok !Devel::PPPort::SVf_IVisUV($negative);
+} else {
+ skip 'SVf_IVisUV is unsupported', 1;
+}
+is tied($negative)->{fetch}, 1;
+is tied($negative)->{store}, 0;
+
+tie my $big, 'TieScalarCounter', Devel::PPPort::above_IV_MAX();
+$fetch = $big;
+
+is tied($big)->{fetch}, 1;
+is tied($big)->{store}, 0;
+Devel::PPPort::magic_SvIV_nomg($big);
+if (ivers($]) >= ivers("5.6")) {
+ ok Devel::PPPort::SVf_IVisUV($big);
+} else {
+ skip 'SVf_IVisUV is unsupported', 1;
+}
+is tied($big)->{fetch}, 1;
+is tied($big)->{store}, 0;
+is Devel::PPPort::magic_SvUV_nomg($big), Devel::PPPort::above_IV_MAX();
+if (ivers($]) >= ivers("5.6")) {
+ ok Devel::PPPort::SVf_IVisUV($big);
+} else {
+ skip 'SVf_IVisUV is unsupported', 1;
+}
+is tied($big)->{fetch}, 1;
+is tied($big)->{store}, 0;
+
+package TieScalarCounter;
+
+sub TIESCALAR {
+ my ($class, $value) = @_;
+ return bless { fetch => 0, store => 0, value => $value }, $class;
+}
+
+sub FETCH {
+ my ($self) = @_;
+ $self->{fetch}++;
+ return $self->{value};
+}
+
+sub STORE {
+ my ($self, $value) = @_;
+ $self->{store}++;
+ $self->{value} = $value;
+}
+
+package OverloadedObject;
+
+sub new {
+ my ($class, $str, $num, $bool) = @_;
+ return bless { str => $str, num => $num, bool => $bool }, $class;
+}
+
+use overload
+ '""' => sub { $_[0]->{str} },
+ '0+' => sub { $_[0]->{num} },
+ 'bool' => sub { $_[0]->{bool} },
+ ;