10
Jun
09

didn’t think I would say wow while reading perl code


Browsing around in stackoverflow, I found a link to MooseX::Declare. How about that perl code ? Nice, right? You bet !

Here’s a small sample from the CPAN page :


    use MooseX::Declare;

    class BankAccount {
        has 'balance' => ( isa => 'Num', is => 'rw', default => 0 );

        method deposit (Num $amount) {
            $self->balance( $self->balance + $amount );
        }

        method withdraw (Num $amount) {
            my $current_balance = $self->balance();
            ( $current_balance >= $amount )
                || confess "Account overdrawn";
            $self->balance( $current_balance - $amount );
        }
    }


0 Responses to “didn’t think I would say wow while reading perl code”



  1. No Comments Yet

Leave a Reply