1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id: Test.pm,v 1.1.2.8 2001/10/25 17:34:42 pudge Exp $
package Slash::Test;
=head1 NAME
Slash::Test - Command-line Slash testing
=head1 SYNOPSIS
% perl -MSlash::Test -wle Display
Current user is [% user.nickname %] ([% user.uid %])
^DCurrent user is Anonymous Coward (1)
% perl -MSlash::Test -e 'print Dumper $user'
% perl -MSlash::Test=virtualuser -e 'print Dumper $user'
#!/usr/bin/perl -w
use Slash::Test qw(virtualuser);
print Dumper $user;
=head1 DESCRIPTION
Will export everything from Slash, Slash::Utility, Slash::Display,
Slash::XML, and Data::Dumper into the current namespace. Will export $user,
$form, $constants, and $slashdb as global variables into the current namespace.
So use it one of three ways (use the default Virtual User,
or pass it in via the import list, or pass in with slashTest()), and then
just use the Slash API in your one-liners.
It is recommended that you change the hardcoded default to whatever
Virtual User you use most.
=head1 EXPORTED FUNCTIONS
=cut
BEGIN { $ENV{TZ} = 'GMT' }
use Slash;
use Slash::Display;
use Slash::Utility;
use Slash::XML;
use Data::Dumper;
use base 'Exporter';
use vars qw($VERSION @EXPORT $vuser);
($VERSION) = ' $Revision: 1.1.2.8 $ ' =~ /\$Revision:\s+([^\s]+)/;
@EXPORT = (
@Slash::EXPORT,
@Slash::Display::EXPORT,
@Slash::Utility::EXPORT,
@Slash::XML::EXPORT,
@Data::Dumper::EXPORT,
'slashTest',
'Display',
);
# "manually" export @EXPORT symbols
Slash::Test->export_to_level(1, '', @EXPORT);
# allow catching of virtual user in import list
sub import {
slashTest($_[1] || 'slash');
}
#========================================================================
=head2 slashTest([VIRTUALUSER])
Set up the environment, with a new Virtual User.
Called automatically when module is first used. Should only be called
if changing the Virtual User from the default (by default, "slash").
Called without an argument, uses the default.
=over 4
=item Parameters
=over 4
=item VIRTUALUSER
Your site's virtual user.
=back
=item Return value
None.
=item Side effects
Set up the environment with createEnvironment(), export $user,
$form, $constants, and $slashdb into current namespace.
=back
=cut
sub slashTest {
my($VirtualUser, $noerr) = @_;
die "No virtual user" unless defined $VirtualUser and $VirtualUser ne "";
eval { createEnvironment($VirtualUser) };
die $@ if $@ && !$noerr;
$::slashdb = getCurrentDB();
$::constants = getCurrentStatic();
$::user = getCurrentUser();
$::form = getCurrentForm();
}
#========================================================================
=head2 Display(TEMPLATE [, HASHREF, RETURN])
A wrapper for slashDisplay(). Pass in a template string (not a template
name) and optional hashref of variables. Nocomm is true. Default is to
print (else make third param true).
If first arg is false, then takes template from STDIN. You can type in
your template on the command line, then, and hit ctrl-D or whatever
to end.
=cut
sub Display {
my($template, $hashref, $return) = @_;
if (!$template) {
$template = '';
while (<>) {
$template .= $_;
}
}
slashDisplay(\$template, $hashref, { Nocomm => 1, Return => $return });
}
1;
__END__
=head1 SEE ALSO
Slash(3).
=head1 VERSION
$Id: Test.pm,v 1.1.2.8 2001/10/25 17:34:42 pudge Exp $
|