$wartung->datum
1 2 3
$wartung->datum = $wartung->datum + '1D' $wartung->datum = date(time) $wartung->datum->add('1D')
$wartung->datum--
$wartung->datum += '1D'
$obj->foo = $obj->foo;
QuoteIf 'fallback' is undefined or TRUE then a copy constructor can be autogenerated, but only for objects based on scalars. In other cases it needs to be defined explicitly. Where an object's data is stored as, for example, an array of scalars, the following might be appropriate:
use overload '=' => sub { bless [ @{$_[0]} ] }, # ...
QuoteIf 'fallback' is TRUE and no copy constructor is defined then, for objects not based on scalars, Perl may silently fall back on simple assignment - that is, assignment of the object reference. In effect, this disables the copy constructor mechanism since no new copy of the object data is created. This is almost certainly not what you want. (It is, however, consistent: for example, Perl's fallback for the "++" operator is to increment the reference itself.)
'=' => sub { print "DRIN\n"; $_[0]->clone },
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
my %t; tie %t, 'TH'; $t{test} = date('2012-01-01'); print $t{test}-=5; # standard hashverhalten package TH; use Tie::Hash; sub TIEHASH { my $self = {}; my $class = shift; bless $self, $class; } sub STORE { $_[0]->{$_[1]} = $_[2]; } sub FETCH { return $_[0]->{$_[1]}; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!env perl use strict; use warnings; use Class::Date qw(date); print "Class::Date: ".$Class::Date::VERSION."\n"; print "Tie::Hash: ".$Tie::Hash::VERSION."\n"; print "OS: $^O\n"; print "PERL: ".(`env perl -v`)[1]."\n"; my %t; tie %t, 'TH'; $t{test} = date('2012-01-01'); print $t{test}." --> "; print $t{test}-=5; # standard hashverhalten package TH; use Tie::Hash; sub TIEHASH { my $self = {}; my $class = shift; bless $self, $class; } sub STORE { $_[0]->{$_[1]} = $_[2]; } sub FETCH { return $_[0]->{$_[1]}; }
1
2
3
4
5
6
Class::Date: 1.1.10
Tie::Hash: 1.04
OS: linux
PERL: This is perl 5, version 14, subversion 2 (v5.14.2) built for i486-linux-gnu-thread-multi-64int
2012-01-01 00:00:00 --> 2011-12-31 23:59:55