[ic] Useful UserTags: [wrapper]
DB
db at m-and-d.com
Sun Mar 5 17:20:47 UTC 2023
On 3/5/23 8:13 AM, Stefan Hornburg (Racke) wrote:
> 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
>
Thanks! Can you (or someone) provide a very brief conceptual explanation
of how one might use this?
DB
More information about the interchange-users
mailing list