2013年3月12日

[Perl] Moose 範例 - 銀行篇

#!/usr/bin/env perl

package BankAccount;
use Moose;
use Data::Dumper;

has 'balance' => (
  is => 'rw',
  isa => 'Str',
  default => 0
);

sub deposit {
  my ($self, $amount) = @_;
  $self->balance( $self->balance + $amount);
}

sub showBalance {
  my $self = @_;
  print "The balance is : \n";
 
}

my $savingAccount = BankAccount->new( balance => 250 );
print Dumper($savingAccount);
$savingAccount->deposit(100);
print Dumper($savingAccount);               
$savingAccount->showBalance();
 

沒有留言:

這個小工具發生錯誤