erlug
[Top] [All Lists]

Re: [Erlug] [OT] Quale linguaggio ?

To: ERlug - Lista Pubblica <erlug@xxxxxxxxxxxxxx>
Subject: Re: [Erlug] [OT] Quale linguaggio ?
From: Fernando Santagata <nando@xxxxxxxxx>
Date: Mon, 12 Dec 2011 10:37:27 +0100
On Sat, Dec 10, 2011 at 12:29:43PM +0100, Jacopo Ghisolfi wrote:
> Ah, prima di chiudere: un paio di link a risorse _fondamentali_ per
> iniziare (oltre a perl.it e perl.org)?

Fatti un regalo ed impara ad usare Moose:

http://search.cpan.org/~doy/Moose-2.0401/lib/Moose.pm

cosi` potrai scrivere le tue classi in questo modo:

package Point;
use Moose; # automatically turns on strict and warnings

has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');

sub clear {
                my $self = shift;
                $self->x(0);
                $self->y(0);
}

package Point3D;
use Moose;

extends 'Point';

has 'z' => (is => 'rw', isa => 'Int');

after 'clear' => sub {
                my $self = shift;
                $self->z(0);
};

Sia gli accessor, che i mutator e il new vengono generati automaticamente
(perche' scivere del codice sempre uguale?).

-- 
Fernando Santagata
Jesus saves, but Buddha makes incremental backups.

<Prev in Thread] Current Thread [Next in Thread>