Hi all

When I pass undef as the value for a component, it is treated as
though it were given a value, and is not assigned a default.

I discovered this when iterating through an array, intending to call
the same component for each one and override defaults only for certain
values in the array.

The code at the end, therefore, will output

<p></p>
<p>baz</p>

for the array

@some_pre_initialised_array = qw( fooisbar fooisbaz )

because when $foo = undef in the loop, $foo is assigned the value
undef (!) between $m->comp and <%$foo%>

My question is, is this expected behaviour? It seems unintuitive to
me: I would have expected the construct

  $foo => "bar"

in <%args%> to be equivalent to

  my $foo = $args->{foo} || "bar"

in a normal function. However, it appears that it is more like

  $foo = (exists $args->{foo}) ? $args->{foo} : 'bar'

If this *is* expected behaviour, which I'm willing to accept, is there
a better way of doing what I'm trying to do (i.e. have a
component-default value unless an overridden one is passed in without
making a mockery of a nice clean loop) without having something like

  <%init>
    $foo = 'bar' unless $foo;
  </%init>

for every argument?

Thanks and goodnight,
Al

--component.html--

<%args>
$foo => 'bar'
</%args>
<p><%$foo%></p>

--

-- calling page --

<%perl>
for (@some_pre_initialised_array) {
  my $foo;
  $foo = 'baz' if m/^fooisbaz$/;
  $m->comp(component.html, foo=>$foo);
}
</%perl>

--

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to