5 # This test file exists to show that Time::Piece can be subclassed and that its
6 # methods will return objects of the class on which they're called.
8 use Test::More 'no_plan';
10 BEGIN { use_ok('Time::Piece'); }
12 my $class = 'Time::Piece::Twin';
14 for my $method (qw(new localtime gmtime)) {
15 my $piece = $class->$method;
16 isa_ok($piece, $class, "timepiece made via $method");
20 my $piece = $class->strptime("2005-01-01", "%Y-%m-%d");
21 isa_ok($piece, $class, "timepiece made via strptime");
25 my $piece = $class->new;
26 isa_ok($piece, $class, "timepiece made via new (again)");
28 my $sum = $piece + 86_400;
29 isa_ok($sum, $class, "tomorrow via addition operator");
31 my $diff = $piece - 86_400;
32 isa_ok($diff, $class, "yesterday via subtraction operator");
36 # let's verify that we can use gmtime from T::P without the export magic
37 my $piece = Time::Piece::gmtime;
38 isa_ok($piece, "Time::Piece", "object created via full-qualified gmtime");
39 isnt(ref $piece, 'Time::Piece::Twin', "it's not a Twin");
42 ## below is our doppelgaenger package
44 package Time::Piece::Twin;
45 use base qw(Time::Piece);
46 # this package is identical, but will be ->isa('Time::Piece::Twin');
50 my $class = "Time::Piece::NumString";
51 my $piece = $class->strptime ("2006", "%Y");
53 "subtract attempts stringify for unrecognized objects.");
56 ## Below is a package which only changes the stringify function.
58 package Time::Piece::NumString;
59 use base qw(Time::Piece);
60 use overload '""' => \&_stringify;
64 return $self->strftime ("%Y");