Class methods and Instance methods



examples/perloop/person09/script/person.pl
use strict;
use warnings;
use v5.10;

use Person;

my $first   = Person->new( name => 'Foo' );
say Person->count;   # 1
{
    my $second  = Person->new( name => 'Bar' );
    say Person->count; # 2
}
say Person->count;  # 2

examples/perloop/person09/lib/Person.pm
package Person;
use strict;
use warnings;

my $count = 0;

sub new {
    my ($class, %args) = @_;

    my $self = \%args;

    bless $self, $class;

    $count++;

    return $self;
}


sub name {
    my ($self, $value) = @_;

    return $self->{name};
}


sub count {
    return $count;
}

1;