| 1 |
#============================================================= -*-Perl-*- |
| 2 |
# |
| 3 |
# Template::Stash::XS |
| 4 |
# |
| 5 |
# DESCRIPTION |
| 6 |
# |
| 7 |
# Perl bootstrap for XS module. Inherits methods from |
| 8 |
# Template::Stash when not implemented in the XS module. |
| 9 |
# |
| 10 |
#======================================================================== |
| 11 |
|
| 12 |
package Template::Stash::XS; |
| 13 |
|
| 14 |
use strict; |
| 15 |
use warnings; |
| 16 |
use Template; |
| 17 |
use Template::Stash; |
| 18 |
|
| 19 |
our $AUTOLOAD; |
| 20 |
|
| 21 |
BEGIN { |
| 22 |
require DynaLoader; |
| 23 |
@Template::Stash::XS::ISA = qw( DynaLoader Template::Stash ); |
| 24 |
|
| 25 |
eval { |
| 26 |
bootstrap Template::Stash::XS $Template::VERSION; |
| 27 |
}; |
| 28 |
if ($@) { |
| 29 |
die "Couldn't load Template::Stash::XS $Template::VERSION:\n\n$@\n"; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
sub DESTROY { |
| 34 |
# no op |
| 35 |
1; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
# catch missing method calls here so perl doesn't barf |
| 40 |
# trying to load *.al files |
| 41 |
|
| 42 |
sub AUTOLOAD { |
| 43 |
my ($self, @args) = @_; |
| 44 |
my @c = caller(0); |
| 45 |
my $auto = $AUTOLOAD; |
| 46 |
|
| 47 |
$auto =~ s/.*:://; |
| 48 |
$self =~ s/=.*//; |
| 49 |
|
| 50 |
die "Can't locate object method \"$auto\"" . |
| 51 |
" via package \"$self\" at $c[1] line $c[2]\n"; |
| 52 |
} |
| 53 |
|
| 54 |
1; |
| 55 |
|
| 56 |
__END__ |
| 57 |
|
| 58 |
=head1 NAME |
| 59 |
|
| 60 |
Template::Stash::XS - High-speed variable stash written in C |
| 61 |
|
| 62 |
=head1 SYNOPSIS |
| 63 |
|
| 64 |
use Template; |
| 65 |
use Template::Stash::XS; |
| 66 |
|
| 67 |
my $stash = Template::Stash::XS->new(\%vars); |
| 68 |
my $tt2 = Template->new({ STASH => $stash }); |
| 69 |
|
| 70 |
=head1 DESCRIPTION |
| 71 |
|
| 72 |
The Template:Stash::XS module is an implementation of the |
| 73 |
Template::Stash written in C. The "XS" in the name refers to Perl's |
| 74 |
XS extension system for interfacing Perl to C code. It works just |
| 75 |
like the regular Perl implementation of Template::Stash but runs about |
| 76 |
twice as fast. |
| 77 |
|
| 78 |
The easiest way to use the XS stash is to configure the Template |
| 79 |
Toolkit to use it by default. You can do this at installation time |
| 80 |
(when you run C<perl Makefile.PL>) by answering 'y' to the questions: |
| 81 |
|
| 82 |
Do you want to build the XS Stash module? y |
| 83 |
Do you want to use the XS Stash by default? y |
| 84 |
|
| 85 |
See the F<INSTALL> file distributed with the Template Toolkit for further |
| 86 |
details on installation. |
| 87 |
|
| 88 |
If you don't elect to use the XS stash by default then you should use |
| 89 |
the C<STASH> configuration item when you create a new Template object. |
| 90 |
This should reference an XS stash object that you have created |
| 91 |
manually. |
| 92 |
|
| 93 |
use Template; |
| 94 |
use Template::Stash::XS; |
| 95 |
|
| 96 |
my $stash = Template::Stash::XS->new(\%vars); |
| 97 |
my $tt2 = Template->new({ STASH => $stash }); |
| 98 |
|
| 99 |
Alternately, you can set the C<$Template::Config::STASH> package |
| 100 |
variable like so: |
| 101 |
|
| 102 |
use Template; |
| 103 |
use Template::Config; |
| 104 |
|
| 105 |
$Template::Config::STASH = 'Template::Stash::XS'; |
| 106 |
|
| 107 |
my $tt2 = Template->new(); |
| 108 |
|
| 109 |
The XS stash will then be automatically used. |
| 110 |
|
| 111 |
If you want to use the XS stash by default and don't want to |
| 112 |
re-install the Template Toolkit, then you can manually modify the |
| 113 |
C<Template/Config.pm> module near line 42 to read: |
| 114 |
|
| 115 |
$STASH = 'Template::Stash::XS'; |
| 116 |
|
| 117 |
=head1 BUGS |
| 118 |
|
| 119 |
Please report bugs to the Template Toolkit mailing list |
| 120 |
[email protected] |
| 121 |
|
| 122 |
=head1 AUTHORS |
| 123 |
|
| 124 |
Andy Wardley E<lt>[email protected]<gt> L<http://wardley.org/> |
| 125 |
|
| 126 |
Doug Steinwand E<lt>[email protected]<gt> |
| 127 |
|
| 128 |
=head1 COPYRIGHT |
| 129 |
|
| 130 |
Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved. |
| 131 |
|
| 132 |
This module is free software; you can redistribute it and/or |
| 133 |
modify it under the same terms as Perl itself. |
| 134 |
|
| 135 |
=head1 SEE ALSO |
| 136 |
|
| 137 |
L<Template::Stash> |