Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have any shot of adding modules to use, try <a href="http://www.iinteractive.com/moose/" rel="noreferrer">Moose</a>. It provides pretty much all the features you'd want in a modern programming environment, and more. It does type checking, excellent inheritance, has introspection capabilities, and with <a href="http://search.cpan.org/perldoc?MooseX::Declare" rel="noreferrer">MooseX::Declare</a>, one of the nicest interfaces for Perl classes out there. Take a look:</p> <pre><code>use MooseX::Declare; class BankAccount { has 'balance' =&gt; ( isa =&gt; 'Num', is =&gt; 'rw', default =&gt; 0 ); method deposit (Num $amount) { $self-&gt;balance( $self-&gt;balance + $amount ); } method withdraw (Num $amount) { my $current_balance = $self-&gt;balance(); ( $current_balance &gt;= $amount ) || confess "Account overdrawn"; $self-&gt;balance( $current_balance - $amount ); } } class CheckingAccount extends BankAccount { has 'overdraft_account' =&gt; ( isa =&gt; 'BankAccount', is =&gt; 'rw' ); before withdraw (Num $amount) { my $overdraft_amount = $amount - $self-&gt;balance(); if ( $self-&gt;overdraft_account &amp;&amp; $overdraft_amount &gt; 0 ) { $self-&gt;overdraft_account-&gt;withdraw($overdraft_amount); $self-&gt;deposit($overdraft_amount); } } } </code></pre> <p>I think it's pretty cool, myself. :) It's a layer over Perl's object system, so it works with stuff you already have (basically.) </p> <p>With Moose, you can create subtypes really easily, so you can make sure your input is valid. Lazy programmers agree: with so little that has to be done to make subtypes work in Moose, it's easier to do them than not! (from <a href="http://search.cpan.org/~flora/Moose/lib/Moose/Cookbook/Basics/Recipe4.pod" rel="noreferrer">Cookbook 4</a>)</p> <pre><code>subtype 'USState' =&gt; as Str =&gt; where { ( exists $STATES-&gt;{code2state}{ uc($_) } || exists $STATES-&gt;{state2code}{ uc($_) } ); }; </code></pre> <p>And Tada, the USState is now a type you can use! No fuss, no muss, and just a small amount of code. It'll throw an error if it's not right, and all the consumers of your class have to do is pass a scalar with that string in it. If it's fine (which it should be...right? :) ) They use it like normal, and your class is protected from garbage. How nice is that!</p> <p>Moose has tons of awesome stuff like this.</p> <p>Trust me. Check it out. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload