Why writing your own "decoder"? You could just borrow the decoder from CGI. I quickly wrote the following example to show how to decode the named parameters (nicely).
use strict; use Data::Dumper; use CGI::Util qw/rearrange/; # when called as a method __PACKAGE__->test( -option1=>'a', -option3=>'c' ); # called as a normal function test( -option1=>'a', -option3=>'c', -option2=>'b' ); # called with unnamed parameters test( 'a', 'b', 'c' ); # our little test method/function sub test { my($self,@p) = self_or_default(@_); my($option1,$option2,$option3,@other) = rearrange([qw/ OPTION1 OPTION2 OPTION3 /],@p); print "\$option1=$option1\n\$option2=$option2\n\$option3=$option3\n\ +n"; } # borrowed from CGI.pm with minor modification ;-) sub self_or_default { my $class = __PACKAGE__; # name of the class, set to main for testin +g return @_ if defined($_[0]) && (!ref($_[0])) && ($_[0] eq $class); my $Q = undef; unless (defined($_[0]) && (ref($_[0]) eq $class || UNIVERSAL::isa($_[0], $class))) { $Q = {}; bless $Q, __PACKAGE__; unshift(@_,$Q); } return wantarray ? @_ : $Q; }
And the output is just what we expected -
$option1=a $option2= $option3=c $option1=a $option2=b $option3=c $option1=a $option2=b $option3=c

In reply to Re: Re: Re: Methods and attributes? by Roger
in thread Methods and attributes? by stonecolddevin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.