0
  0   ˆl–Ãa¾”TËmJiAã.Ü TÅ£Á„n8ß_‹uÐb&=LV[(ÁÀ =1    #============================================================= -*-Perl-*-
#
# Template::VMethods
#
# DESCRIPTION
#   Module defining virtual methods for the Template Toolkit
#
# AUTHOR
#   Andy Wardley   <abw@wardley.org>
#
# COPYRIGHT
#   Copyright (C) 1996-2022 Andy Wardley.  All Rights Reserved.
#
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
#============================================================================

package Template::VMethods;

use strict;
use warnings;
use Scalar::Util qw( blessed looks_like_number );
use Template::Filters;

our $VERSION = '3.100';
our $DEBUG   = 0 unless defined $DEBUG;

our $ROOT_VMETHODS = {
    inc     => \&root_inc,
    dec     => \&root_dec,
};

our $TEXT_VMETHODS = {
    item        => \&text_item,
    list        => \&text_list,
    hash        => \&text_hash,
    length      => \&text_length,
    size        => \&text_size,
    empty       => \&text_empty,
    defined     => \&text_defined,
    upper       => \&text_upper,
    lower       => \&text_lower,
    ucfirst     => \&text_ucfirst,
    lcfirst     => \&text_lcfirst,
    match       => \&text_match,
    search      => \&text_search,
    repeat      => \&text_repeat,
    replace     => \&text_replace,
    remove      => \&text_remove,
    split       => \&text_split,
    chunk       => \&text_chunk,
    substr      => \&text_substr,
    trim        => \&text_trim,
    collapse    => \&text_collapse,
    squote      => \&text_squote,
    dquote      => \&text_dquote,
    html        => \&Template::Filters::html_filter,
    xml         => \&Template::Filters::xml_filter,
};

our $HASH_VMETHODS = {
    item    => \&hash_item,
    hash    => \&hash_hash,
    size    => \&hash_size,
    empty   => \&hash_empty,
    each    => \&hash_each,
    keys    => \&hash_keys,
    values  => \&hash_values,
    items   => \&hash_items,
    pairs   => \&hash_pairs,
    list    => \&hash_list,
    exists  => \&hash_exists,
    defined => \&hash_defined,
    delete  => \&hash_delete,
    import  => \&hash_import,
    sort    => \&hash_sort,
    nsort   => \&hash_nsort,
};

our $LIST_VMETHODS = {
    item    => \&list_item,
    list    => \&list_list,
    hash    => \&list_hash,
    push    => \&list_push,
    pop     => \&list_pop,
    unshift => \&list_unshift,
    shift   => \&list_shift,
    max     => \&list_max,
    size    => \&list_size,
    empty   => \&list_empty,
    defined => \&list_defined,
    first   => \&list_first,
    last    => \&list_last,
    reverse => \&list_reverse,
    grep    => \&list_grep,
    join    => \&list_join,
    sort    => \&list_sort,
    nsort   => \&list_nsort,
    unique  => \&list_unique,
    import  => \&list_import,
    merge   => \&list_merge,
    slice   => \&list_slice,
    splice  => \&list_splice,
};

# Template::Stash needs the above, so defer loading this module
# until they are defined.
require Template::Stash;
our $PRIVATE = $Template::Stash::PRIVATE;

#========================================================================
# root virtual methods
#========================================================================

sub root_inc {
    no warnings;
    my $item = shift;
    ++$item;
}

sub root_dec {
    no warnings;
    my $item = shift;
    --$item;
}


#========================================================================
# text virtual methods
#========================================================================

sub text_item {
    $_[0];
}

sub text_list {
    [ $_[0] ];
}

sub text_hash {
    { value => $_[0] };
}

sub text_length {
    length $_[0];
}

sub text_size {
    return 1;
}

sub text_empty {
    return 0 == text_length($_[0]) ? 1 : 0;
}

sub text_defined {
    return 1;
}

sub text_upper {
    return uc $_[0];
}

sub text_lower {
    return lc $_[0];
}

sub text_ucfirst {
    return ucfirst $_[0];
}

sub text_lcfirst {
    return lcfirst $_[0];
}

sub text_trim {
    for ($_[0]) {
        s/^\s+//;
        s/\s+$//;
