Sub::ParamLoader version 0.01 - Map named argument list into a hash modified according to a rule ============================================================================ SYNOPSIS use Sub::ParamLoader; my $pl = Sub::ParamLoader -> new ('D'=>[...],'M'=>...); # parameters specify the rule described below my $HashObject = $pl->load(...,key=>value,..); # store named items # access as usual with hash my $v = $HashObject->{key}; my @V = delete @$HashObject{..,key,..}; DESCRIPTION Arguments of the constructor, keyed by 'D','M', are optional. Giving a closer view they look like 'D' => [...,Name(i)=>DefVal(i),...] 'M' => $mask where $mask = sub {...} 'M' => [ $mask, P(1),...P(m) ] or = \&fmask The arguments and specifications are exactly as in Sub::ParamFrame by correspondence of operations : Sub::ParamFrame Sub::ParamLoader ----------------------------------------------- pfrule new pfload load This class provides base functionality for "Sub::ParamFrame" which only adds a final improvement step for subroutine arguments. Regarding methods "new & load", as contents overlap, please refer to the description of "pfrule & pfload" in Sub::ParamFrame. Note that in "Sub::ParamFrame" "pfrule" calls "Sub::ParamLoader->new(...)" storing the created object to $register{$subname}, "pfload" invokes "$register{$subname}->load". DEPENDENCIES This module requires these other modules and libraries: "Tie::Hash::KeysMask" EXAMPLE use Sub::ParamLoader; my @DoW = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday); my %DW2Dic = ######### Abbreviations mapping ############# qw(su sunday mo monday tu tuesday we wednesday th thursday fr friday sa saturday); my $pl = Sub::ParamLoader->new #============== RULE ============# ( #------------------ KEYMASK--'M'------------------# 'M' => # match any prefix-string of a week-day-name with legth sub # not less than 2, ignoring case of characters { my $ik = shift; my $ikl = lc $ik; my $ikl2 = substr $ikl,0,2; my $res = $DW2Dic{$ikl2}; return undef unless ( defined $res) && ($ikl eq substr($res,0,length $ikl)); $res; }, 'D' => [qw(SUN VII MON I TUE II WED III)] ### DEFAULTS ### ); my $hob = $pl->load qw(We iii Thur iv Fr v Satur vi Sun vii); # overrides defauts 'wednesday'=>'III','sunday'=>'VII' # sub bar; sub kvTabPrint; ######## show variants of access ####### print bar 7; kvTabPrint $hob, @DoW; kvTabPrint $hob, qw (mo tu we th fr sa su); kvTabPrint $hob, qw (MONDY1 TUE WEDNESD THI FRI SAT suN); kvTabPrint $hob, qw (Mond TUE We th Fridy1 saturn sUn); ###################### output printing matters #################### sub lf() {qq(\n)} sub bar { sub seg() {'-'x10} sub segv() {seg.'+'} my $n = (shift)-1; (segv x $n).seg.lf; } sub kvTabPrint ######## output a hash arguments-values table ##### { my $href = shift; my $kline = join ' |', map sprintf('%9s',$_),@_; my $vline = join ' |', map sprintf('%9s',$href->{$_}||'?'),@_; print $kline,lf,$vline,lf,bar(scalar @_); } ################################################################### Output of last call of kvTabPrint: ---------+----------+----------+----------+----------+----------+---------- Mond | TUE | We | th | Fridy1 | saturn | sUn I | II | iii | iv | ? | ? | vii ---------+----------+----------+----------+----------+----------+---------- AUTHOR Josef Schönbrunner COPYRIGHT AND LICENSE Copyright (c) 2005 by Josef Schönbrunner This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.