Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 imbibing at the Monastery: (4)
As of 2015-07-28 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls