MASON getting arguments.

Discussion in 'Perl Misc' started by bpatton, Jun 21, 2007.

  1. bpatton

    bpatton Guest

    I know that all the values passed into a module are in @_
    assume @_ looks like [ c , 3 , d , 4 ]
    But between
    <%args>
    $a => 1;
    $b => 2;
    </%args>

    How do I get the variables $a and $b and their values when they may
    not have been passed in?
    bpatton, Jun 21, 2007
    #1
    1. Advertising

  2. bpatton wrote:
    > I know that all the values passed into a module are in @_


    They aren't. All the values passed to a _sub_ are in @_.

    > assume @_ looks like [ c , 3 , d , 4 ]


    Do you mean ( 'c', 3, 'd', 4 ) ?

    > But between
    > <%args>
    > $a => 1;
    > $b => 2;
    > </%args>


    <%args> and </%args> is not Perl code, AFAIK.

    > How do I get the variables $a and $b and their values when they may
    > not have been passed in?


    Sorry, I'm lost.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jun 21, 2007
    #2
    1. Advertising

  3. bpatton

    Xicheng Jia Guest

    On Jun 21, 4:05 pm, bpatton <> wrote:
    > I know that all the values passed into a module are in @_
    > assume @_ looks like [ c , 3 , d , 4 ]


    ITYM: "passed into a Mason component"

    > But between
    > <%args>
    > $a => 1;
    > $b => 2;


    no trailing semi-colon please..

    > </%args>
    >
    > How do I get the variables $a and $b and their values when they may
    > not have been passed in?


    $a is 1 and $b is 2 by default. check the following link.

    http://www.masonbook.com/book/chapter-2.mhtml#TOC-ANCHOR-9

    Regards,
    Xicheng
    Xicheng Jia, Jun 21, 2007
    #3
  4. bpatton

    bpatton Guest

    On Jun 21, 3:32 pm, Xicheng Jia <> wrote:
    > On Jun 21, 4:05 pm, bpatton <> wrote:
    >
    > > I know that all the values passed into a module are in @_
    > > assume @_ looks like [ c , 3 , d , 4 ]

    >
    > ITYM: "passed into a Mason component"
    >
    > > But between
    > > <%args>
    > > $a => 1;
    > > $b => 2;

    >
    > no trailing semi-colon please..
    >
    > > </%args>

    >
    > > How do I get the variables $a and $b and their values when they may
    > > not have been passed in?

    >
    > $a is 1 and $b is 2 by default. check the following link.
    >
    > http://www.masonbook.com/book/chapter-2.mhtml#TOC-ANCHOR-9
    >
    > Regards,
    > Xicheng


    I read the pages, no help.
    I guess I need to re sum what I'm after
    Assume I have this mason file:
    <%args>
    $a
    $b
    $c => 3
    $d => 4
    </%args>

    Now I have a perl function that needs the input of %args to/%args and
    their default value.

    I know this works
    myRoutine('a' => $a,
    'b' => $b,
    'c' => $c,
    'd' => $d);

    in perl
    sub myRoutine {
    my %args = @_;
    ....
    }


    THere are about 40 of these mason files that have different <
    %args> ... </%args> within them. I'm trying to reuse as much code as
    possible and cut down on the number of places I have to mainitain so
    what I'm looking for is something to the effect of

    <%args>
    $a
    $b
    $c => 3
    $d => 4
    </%args>

    myRoutine(\%ARGS);

    But %ARGS or @_ may not contain c and d unless they were passed in.
    myRoutine needs all arguments, in %ARGS and between %args and /%args.
    %ARGS and @_ will contain the manditory input, not the input with
    default values.
    bpatton, Jun 22, 2007
    #4
  5. bpatton

    Xicheng Jia Guest

    On Jun 22, 6:31 am, bpatton <> wrote:
    > On Jun 21, 3:32 pm, Xicheng Jia <> wrote:
    >
    >
    >
    >
    >
    > > On Jun 21, 4:05 pm, bpatton <> wrote:

    >
    > > > I know that all the values passed into a module are in @_
    > > > assume @_ looks like [ c , 3 , d , 4 ]

    >
    > > ITYM: "passed into a Mason component"

    >
    > > > But between
    > > > <%args>
    > > > $a => 1;
    > > > $b => 2;

    >
    > > no trailing semi-colon please..

    >
    > > > </%args>

    >
    > > > How do I get the variables $a and $b and their values when they may
    > > > not have been passed in?

    >
    > > $a is 1 and $b is 2 by default. check the following link.

    >
    > >http://www.masonbook.com/book/chapter-2.mhtml#TOC-ANCHOR-9

    >
    > > Regards,
    > > Xicheng

    >
    > I read the pages, no help.
    > I guess I need to re sum what I'm after
    > Assume I have this mason file:
    > <%args>
    > $a
    > $b
    > $c => 3
    > $d => 4
    > </%args>
    >
    > Now I have a perl function that needs the input of %args to/%args and
    > their default value.
    >
    > I know this works
    > myRoutine('a' => $a,
    > 'b' => $b,
    > 'c' => $c,
    > 'd' => $d);
    >
    > in perl
    > sub myRoutine {
    > my %args = @_;
    > ...
    >
    > }
    >
    > THere are about 40 of these mason files that have different <
    > %args> ... </%args> within them. I'm trying to reuse as much code as
    > possible and cut down on the number of places I have to mainitain so
    > what I'm looking for is something to the effect of
    >
    > <%args>
    > $a
    > $b
    > $c => 3
    > $d => 4
    > </%args>
    >
    > myRoutine(\%ARGS);
    >
    > But %ARGS or @_ may not contain c and d unless they were passed in.
    > myRoutine needs all arguments, in %ARGS and between %args and /%args.
    > %ARGS and @_ will contain the manditory input, not the input with
    > default values.- Hide quoted text -
    >
    > - Show quoted text -


    hmm, from my understanding, %ARGS contains only request params(like
    those appeared in $m->request_args). If you want to visit all
    parameters defined in <%args> block, you probably can use $m-
    >current_comp->declared_args, check the page


    http://www.masonhq.com/docs/manual/Component.html

    #########################
    declared_args

    Returns a reference to a hash of hashes representing the arguments
    declared in the <%args> section. The keys of the main hash are the
    variable names including prefix (e.g. $foo, @list)....
    #########################

    it might be close to your needs..

    Regards,
    Xicheng
    Xicheng Jia, Jun 22, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mills Thomas (app1tam)

    Anything like Mason in Ruby?

    Mills Thomas (app1tam), Aug 5, 2003, in forum: Ruby
    Replies:
    1
    Views:
    91
    Aredridel
    Aug 6, 2003
  2. Asby

    Mason, DBI, and DBI::Pg

    Asby, Jul 24, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    167
  3. Matija Papec

    Mason pipeline style

    Matija Papec, Oct 20, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    79
    Matija Papec
    Oct 25, 2003
  4. John Bokma

    Mason book available as PDF file?

    John Bokma, Oct 18, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    113
    Ala Qumsieh
    Oct 18, 2004
  5. Mason hosting support?

    , Feb 19, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    84
    John Bokma
    Feb 21, 2005
Loading...

Share This Page