今回は大した変更をしていません。
lib/Money.pm
timesメソッドでDollarクラスを返すよう変更しました。
package Money; use strict; use warnings; use version; our $VERSION = qv('0.0.3'); 1; package Dollar; use strict; use warnings; sub new { my ($class, $opts) =(@_); return bless $opts, $class; } sub times { my ($self, $multiplier) = (@_); return new Dollar({amount => $self->{amount} * $multiplier}); } 1;
t/01money.t
テストプラン数をTest識別子?の後に明示的に記述しています。
use strict; use warnings; use Test::Class; Test::Class->runtests; package TestMoney; use strict; use warnings; use base 'Test::Class'; use Money; use Test::More; sub test_multiplication : Test(2) { my $five = new Dollar({amount => 5}); my $product = $five->times(2); is($product->{amount}, 10); $product = $five->times(3); is($product->{amount}, 15); } 1;