This tag makes it very easy to create an arbitrary object with initial parameters:
UserTag email_with_unicode AddAttr
UserTag email_with_unicode Routine <<EOR
sub {
my ($args) = @_;
my %all = %$args;
if ($all{html} and !$all{body}) {
$all{body} = $Tag->wrapper('HTML::FormatText::WithLinks')->parse($all{html});
}
...
Requirements: Perl module in Interchange search path and:
AllowGlobal mycat
PerlAlwaysGlobal mycat
The (global) wrapper tag:
UserTag wrapper Order class
UserTag wrapper AddAttr
UserTag wrapper Routine <<EOR
sub {
my ($class, $opt) = @_;
my (%args, $object, $scratch_var);
# copy tag attributes, drop class and reparse
%args = %$opt if $opt;
delete $args{class};
delete $args{reparse};
$scratch_var = delete $args{scratch};
# load class
eval "require $class";
if ($@) {
die "[wrapper]: Failed to load class $class: $@";
}
eval {
$object = $class->new(%args);
};
if ($@) {
die "[wrapper] Failed to instantiate class $class: $@";
}
if ($scratch_var) {
$Scratch->{$scratch_var} = $object;
}
return $object;
}
EOR
--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper
_______________________________________________
interchange-users mailing list
interchange-users@interchangecommerce.org
https://www.interchangecommerce.org/mailman/listinfo/interchange-users
UserTag email_with_unicode AddAttr
UserTag email_with_unicode Routine <<EOR
sub {
my ($args) = @_;
my %all = %$args;
if ($all{html} and !$all{body}) {
$all{body} = $Tag->wrapper('HTML::FormatText::WithLinks')->parse($all{html});
}
...
Requirements: Perl module in Interchange search path and:
AllowGlobal mycat
PerlAlwaysGlobal mycat
The (global) wrapper tag:
UserTag wrapper Order class
UserTag wrapper AddAttr
UserTag wrapper Routine <<EOR
sub {
my ($class, $opt) = @_;
my (%args, $object, $scratch_var);
# copy tag attributes, drop class and reparse
%args = %$opt if $opt;
delete $args{class};
delete $args{reparse};
$scratch_var = delete $args{scratch};
# load class
eval "require $class";
if ($@) {
die "[wrapper]: Failed to load class $class: $@";
}
eval {
$object = $class->new(%args);
};
if ($@) {
die "[wrapper] Failed to instantiate class $class: $@";
}
if ($scratch_var) {
$Scratch->{$scratch_var} = $object;
}
return $object;
}
EOR
--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper
_______________________________________________
interchange-users mailing list
interchange-users@interchangecommerce.org
https://www.interchangecommerce.org/mailman/listinfo/interchange-users