MASON getting arguments.

B

bpatton

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?
 
G

Gunnar Hjalmarsson

bpatton said:
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>

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

Sorry, I'm lost.
 
X

Xicheng Jia

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
 
B

bpatton

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..
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.
 
X

Xicheng Jia

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"
no trailing semi-colon please..
$a is 1 and $b is 2 by default. check the following link.

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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top