Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Module to Check Constructors?

by Arunbear (Parson)
on Mar 09, 2012 at 17:59 UTC ( #958765=note: print w/ replies, xml ) Need Help??


in reply to Module to Check Constructors?

Yes, see e.g. Params::Validate

update
An example:
#!/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';


Comment on Re: Module to Check Constructors?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://958765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-30 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls