1package DateTime::Format::Natural::Wrappers; 2 3use strict; 4use warnings; 5 6our $VERSION = '0.03'; 7 8sub _add 9{ 10 my $self = shift; 11 $self->_math(@_); 12} 13 14sub _subtract 15{ 16 my $self = shift; 17 $self->_math(@_); 18} 19 20sub _math 21{ 22 my $self = shift; 23 my ($unit, $value) = @_; 24 25 my ($method) = (caller(1))[3] =~ /.+::(.+)$/; 26 $method =~ s/^_//; 27 28 $unit .= 's' unless $unit =~ /s$/; 29 $self->{datetime}->$method($unit => $value); 30 31 chop $unit; 32 $self->{modified}{$unit}++; 33} 34 35sub _add_or_subtract 36{ 37 my $self = shift; 38 39 if (ref $_[0] eq 'HASH') { 40 my %opts = %{$_[0]}; 41 if ($opts{when} > 0) { 42 $self->_add($opts{unit} => $opts{value}); 43 } 44 elsif ($opts{when} < 0) { 45 $self->_subtract($opts{unit} => $opts{value}); 46 } 47 } 48 elsif (@_ == 2) { 49 # Handle additions as expected and also subtractions 50 # as the inverse result of adding a negative number. 51 $self->_add(@_); 52 } 53} 54 55sub _set 56{ 57 my $self = shift; 58 my %values = @_; 59 60 $self->{datetime}->set(%values); 61 62 foreach my $unit (keys %values) { 63 $self->{modified}{$unit}++; 64 } 65} 66 671; 68__END__ 69 70=head1 NAME 71 72DateTime::Format::Natural::Wrappers - Wrappers for DateTime operations 73 74=head1 SYNOPSIS 75 76 Please see the DateTime::Format::Natural documentation. 77 78=head1 DESCRIPTION 79 80The C<DateTime::Format::Natural::Wrappers> class provides internal wrappers 81for DateTime operations. 82 83=head1 SEE ALSO 84 85L<DateTime::Format::Natural> 86 87=head1 AUTHOR 88 89Steven Schubiger <schubiger@cpan.org> 90 91=head1 LICENSE 92 93This program is free software; you may redistribute it and/or 94modify it under the same terms as Perl itself. 95 96See L<http://dev.perl.org/licenses/> 97 98=cut 99