GRAYBYTE WORDPRESS FILE MANAGER9319

Server IP : 149.255.58.128 / Your IP : 216.73.216.117
System : Linux cloud516.thundercloud.uk 5.14.0-427.26.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 17 15:51:13 EDT 2024 x86_64
PHP Version : 8.2.28
Disable Function : allow_url_include, apache_child_terminate, apache_setenv, exec, passthru, pcntl_exec, posix_kill, posix_mkfifo, posix_getpwuid, posix_setpgid, posix_setsid, posix_setuid, posix_setgid, posix_seteuid, posix_setegid, posix_uname, proc_close, proc_get_status, proc_open, proc_terminate, shell_exec, show_source, system
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /usr/local/lib64/perl5/5.32/Template/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /usr/local/lib64/perl5/5.32/Template//Base.pm
#============================================================= -*-perl-*-
#
# Template::Base
#
# DESCRIPTION
#   Base class module implementing common functionality for various other
#   Template Toolkit modules.
#
# 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::Base;

use strict;
use warnings;
use Template::Constants;

our $VERSION = '3.100';


#------------------------------------------------------------------------
# new(\%params)
#
# General purpose constructor method which expects a hash reference of
# configuration parameters, or a list of name => value pairs which are
# folded into a hash.  Blesses a hash into an object and calls its
# _init() method, passing the parameter hash reference.  Returns a new
# object derived from Template::Base, or undef on error.
#------------------------------------------------------------------------

sub new {
    my $class = shift;
    my ($argnames, @args, $arg, $cfg);
#    $class->error('');         # always clear package $ERROR var?

    {   no strict 'refs';
        no warnings 'once';
        $argnames = \@{"$class\::BASEARGS"} || [ ];
    }

    # shift off all mandatory args, returning error if undefined or null
    foreach $arg (@$argnames) {
        return $class->error("no $arg specified")
            unless ($cfg = shift);
        push(@args, $cfg);
    }

    # fold all remaining args into a hash, or use provided hash ref
    $cfg  = defined $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ };

    my $self = bless {
        (map { ($_ => shift @args) } @$argnames),
        _ERROR  => '',
        DEBUG   => 0,
    }, $class;

    return $self->_init($cfg) ? $self : $class->error($self->error);
}


#------------------------------------------------------------------------
# error()
# error($msg, ...)
#
# May be called as a class or object method to set or retrieve the
# package variable $ERROR (class method) or internal member
# $self->{ _ERROR } (object method).  The presence of parameters indicates
# that the error value should be set.  Undef is then returned.  In the
# absence of parameters, the current error value is returned.
#------------------------------------------------------------------------

sub error {
    my $self = shift;
    my $errvar;

    {
        no strict qw( refs );
        $errvar = ref $self ? \$self->{ _ERROR } : \${"$self\::ERROR"};
    }
    if (@_) {
        $$errvar = ref($_[0]) ? shift : join('', @_);
        return undef;
    }
    else {
        return $$errvar;
    }
}


#------------------------------------------------------------------------
# _init()
#
# Initialisation method called by the new() constructor and passing a
# reference to a hash array containing any configuration items specified
# as constructor arguments.  Should return $self on success or undef on
# error, via a call to the error() method to set the error message.
#------------------------------------------------------------------------

sub _init {
    my ($self, $config) = @_;
    return $self;
}


sub debug {
    my $self = shift;
    my $msg  = join('', @_);
    my ($pkg, $file, $line) = caller();

    unless (substr($msg,-1) eq "\n") {
        $msg .= ($self->{ DEBUG } & Template::Constants::DEBUG_CALLER)
            ? " at $file line $line\n"
            : "\n";
    }

    print STDERR "[$pkg] $msg";
}


#------------------------------------------------------------------------
# module_version()
#
# Returns the current version number.
#------------------------------------------------------------------------

sub module_version {
    my $self = shift;
    my $class = ref $self || $self;
    no strict 'refs';
    return ${"${class}::VERSION"};
}

sub DESTROY { 1 } # noop

1;

__END__

=head1 NAME

Template::Base - Base class module implementing common functionality

=head1 SYNOPSIS

    package My::Module;
    use base qw( Template::Base );

    sub _init {
        my ($self, $config) = @_;
        $self->{ doodah } = $config->{ doodah }
            || return $self->error("No 'doodah' specified");
        return $self;
    }

    package main;

    my $object = My::Module->new({ doodah => 'foobar' })
        || die My::Module->error();

=head1 DESCRIPTION

Base class module which implements a constructor and error reporting
functionality for various Template Toolkit modules.

=head1 PUBLIC METHODS

=head2 new(\%config)

Constructor method which accepts a reference to a hash array or a list
of C<name =E<gt> value> parameters which are folded into a hash.  The
C<_init()> method is then called, passing the configuration hash and should
return true/false to indicate success or failure.  A new object reference
is returned, or undef on error.  Any error message raised can be examined
via the L<error()> class method or directly via the C<$ERROR> package variable
in the derived class.

    my $module = My::Module->new({ ... })
        || die My::Module->error(), "\n";

    my $module = My::Module->new({ ... })
        || die "constructor error: $My::Module::ERROR\n";

=head2 error($msg, ...)

May be called as an object method to get/set the internal C<_ERROR> member
or as a class method to get/set the C<$ERROR> variable in the derived class's
package.

    my $module = My::Module->new({ ... })
        || die My::Module->error(), "\n";

    $module->do_something()
        || die $module->error(), "\n";

When called with parameters (multiple params are concatenated), this
method will set the relevant variable and return undef.  This is most
often used within object methods to report errors to the caller.

    package My::Module;

    sub foobar {
        my $self = shift;

        # some other code...

        return $self->error('some kind of error...')
            if $some_condition;
    }

=head2 debug($msg, ...)

Generates a debugging message by concatenating all arguments
passed into a string and printing it to C<STDERR>.  A prefix is
added to indicate the module of the caller.

    package My::Module;

    sub foobar {
        my $self = shift;

        $self->debug('called foobar()');

        # some other code...
    }

When the C<foobar()> method is called, the following message
is sent to C<STDERR>:

    [My::Module] called foobar()

Objects can set an internal C<DEBUG> value which the C<debug()>
method will examine.  If this value sets the relevant bits
to indicate C<DEBUG_CALLER> then the file and line number of
the caller will be append to the message.

    use Template::Constants qw( :debug );

    my $module = My::Module->new({
        DEBUG => DEBUG_SERVICE | DEBUG_CONTEXT | DEBUG_CALLER,
    });

    $module->foobar();

This generates an error message such as:

    [My::Module] called foobar() at My/Module.pm line 6

=head2 module_version()

Returns the version number for a module, as defined by the C<$VERSION>
package variable.

=head1 AUTHOR

Andy Wardley E<lt>abw@wardley.orgE<gt> L<http://wardley.org/>

=head1 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.

=head1 SEE ALSO

L<Template>

=cut

# Local Variables:
# mode: perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# vim: expandtab shiftwidth=4:

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
May 03 2024 07:59:25
0 / root
0755
Manual
--
February 06 2024 22:25:04
0 / root
0755
Namespace
--
February 06 2024 22:25:04
0 / root
0755
Plugin
--
February 06 2024 22:25:04
0 / root
0755
Stash
--
February 06 2024 22:25:04
0 / root
0755
Tools
--
February 06 2024 22:25:04
0 / root
0755
Tutorial
--
February 06 2024 22:25:04
0 / root
0755
Base.pm
7.352 KB
July 26 2022 06:34:37
0 / root
0444
Config.pm
13.382 KB
February 06 2024 22:25:00
0 / root
0444
Constants.pm
9.394 KB
July 26 2022 06:34:56
0 / root
0444
Context.pm
51.183 KB
July 26 2022 06:57:32
0 / root
0444
Directive.pm
28.797 KB
July 26 2022 06:35:23
0 / root
0444
Document.pm
15.978 KB
July 26 2022 07:31:39
0 / root
0444
Exception.pm
6.222 KB
July 26 2022 06:35:49
0 / root
0444
FAQ.pod
8.617 KB
July 26 2022 06:36:02
0 / root
0444
Filters.pm
24.416 KB
July 26 2022 06:36:15
0 / root
0444
Grammar.pm
96.518 KB
July 26 2022 06:36:35
0 / root
0444
Iterator.pm
13.153 KB
July 26 2022 06:58:58
0 / root
0444
Manual.pod
2.371 KB
July 26 2022 06:36:54
0 / root
0444
Modules.pod
5.368 KB
July 26 2022 06:37:07
0 / root
0444
Parser.pm
39.678 KB
July 26 2022 08:28:42
0 / root
0444
Plugin.pm
8.742 KB
July 26 2022 06:37:46
0 / root
0444
Plugins.pm
13.757 KB
July 26 2022 07:00:17
0 / root
0444
Provider.pm
45.427 KB
July 26 2022 07:01:35
0 / root
0444
Service.pm
17.292 KB
July 26 2022 07:01:52
0 / root
0444
Stash.pm
28.15 KB
July 26 2022 07:03:29
0 / root
0444
Test.pm
21.642 KB
July 26 2022 07:04:18
0 / root
0444
Toolkit.pm
5.592 KB
July 26 2022 06:39:17
0 / root
0444
Tools.pod
1.491 KB
July 26 2022 06:39:24
0 / root
0444
Tutorial.pod
1.018 KB
July 26 2022 06:39:32
0 / root
0444
VMethods.pm
15.299 KB
July 26 2022 07:08:17
0 / root
0444
View.pm
23.449 KB
July 26 2022 07:06:24
0 / root
0444

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF