my $person = People
->new
->first_name( 'Tommy' )
->last_name( 'Atkins' )
->email( 'dev@null.com' )
->save;
my $id = $person->get_id;
####
my $person = People->new( $id );
print $person->first_name, ' ', $person->last_name;
##
##
class People {
// Java constructors have the same name as the class
// People person = new People();
// People person = new People(id);
public People() {
// initialize empty object
}
public People( int id ) {
// we can now access an object by id
}
}
##
##
sub new {
my ($class,$id) = @_;
my %data;
%data = $class->_initialize($id) if $id;
bless \%data, $class;
}
##
##
# no! If this is mapping to a database, you probably don't
# want them to be able to change the id
$person->id( $id );