#!/usr/bin/perl use strict; use warnings; use v5.10; package Player; use Params::Validate qw(:all); sub new { my $class = shift; my %attr = validate(@_, {name => 1, race => 1}); return bless \%attr => $class; } package main; my $player = Player->new(race => 'Elf', name => 'Legolas'); # dies: missing attribute my $player2 = Player->new(race => 'Dwarf'); # dies: unknown attribute my $player3 = Player->new(race => 'Hobbit', name => 'Bilbo Baggins', s +ize => 'small'); say 'done';
In reply to Re: Module to Check Constructors?
by Arunbear
in thread Module to Check Constructors?
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |