Here's some ideas...
use strict; use warnings; { package Fake::Object; use Data::Dumper; sub new { shift; print Dumper +{ @_ }; } } my $var1 = "foo"; my $var2 = ""; # As you might expect... # Fake::Object->new( var1 => $var1, var2 => $var2, ); # Use the so-called "enterprise operator" # Fake::Object->new( var1 => $var1, (var2 => $var2) x!!( $var2 ne "" ), ); # PerlX::Maybe has a "provided" function which, # if the first argument is true returns the other # two arguments, and if the first argument is # false returns the empty list. # use PerlX::Maybe qw( provided ); Fake::Object->new( var1 => $var1, provided $var2 ne "", var2 => $var2, );
In reply to Re: Optionally include named arguments when constructing a new object
by tobyink
in thread Optionally include named arguments when constructing a new object
by nice_iguana
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |