sub greet { my ($name, $age) = @_; # required param $name or die "must supply name" ; # optional param, defaults to 25 $age ||= 25; print "Hello, there $name. How does it feel to be $age?\n"; } #### use Params::Validate qw(:all); sub greet { my %p = validate(@_, { name => 1, # required age => { default => 25 } }) } print "Hello, there $name. How does it feel to be $age?\n"; #### sub HTML::Element::iter2 { my $tree = shift; my %p = validate( @_, { # the container look-down. defaults to ['_tag' => 'dl'] wrapper_ld => { default => ['_tag' => 'dl'] }, # the data to fill the container with. mandatory wrapper_data => 1, # the routine to preprocess the HTML::Element container # by default no preprocessing is done wrapper_proc => { default => undef }, # the routine to find the "templated" sub-elements of container # by default returns an arrayref consisting on the dt and dd tags item_ld => { default => sub { my $tree = shift; [ $tree->look_down('_tag' => 'dt'), $tree->look_down('_tag' => 'dd') ]; } }, # the routine to return a row of data from wrapper_data # the default routine simply shifts off a row. you might # replace this with $wrapper_data->next in some cases item_data => { default => sub { my ($wrapper_data) = @_; shift(@{$wrapper_data}) ; }}, # the routine to take the row of data and populate the item tags # the default routine takes a two-element array and fills the # dt and dd tags item_proc => { default => sub { my ($item_elems, $item_data, $row_count) = @_; $item_elems->[$_]->replace_content($item_data->[$_]) for (0,1) ; $item_elems; }}, # the routine to place the accumulated item rows back in the the # HTML::Tree. By default removes the two sample rows (dt and dd) # and replaces them with all the item rows splice => { default => sub { my ($container, @item_elems) = @_; $container->splice_content(0, 2, @item_elems); } }, # output debug info? by default, no debug => {default => 0}