Subject: | [PATCH] efficiency |
This patch addresses two things:
* Do not use Carp and FileHandle, but rather require these packages when
needed. This is especially useful for small systems, where only a
subset of perl modules are installed, and where RAM is limited
* Do not use $& in regexps, this is a performance hit.
Regards,
Slaven
--- ScriptTemplate.pm Fri Dec 14 08:13:13 2001
+++ /home/e/eserte/src/bbbike/lib/Text/ScriptTemplate.pm Thu Dec 20 23:30:31 2001
@@ -159,14 +159,11 @@ Following methods are currently availabl
=cut
-use Carp;
-use FileHandle;
-
use strict;
use vars qw($DEBUG $VERSION);
$DEBUG = 0;
-$VERSION = '0.07';
+$VERSION = '0.07_02';
=item $tmpl = new Text::ScriptTemplate;
@@ -226,7 +223,8 @@ sub load {
my $self = shift;
my $file = shift;
- $file = new FileHandle($file) || croak($!) unless ref($file);
+ require FileHandle;
+ $file = new FileHandle($file) || do { require Carp; Carp::croak($!) } unless ref($file);
$self->pack(join("", <$file>), @_);
}
@@ -262,7 +260,7 @@ sub pack {
## match: ... <% or ...
elsif ($buff =~ s|^(.*?)(?=$L)||s) {
if ($temp = $1) {
- $temp =~ s|[\{\}]|\\$&|g;
+ $temp =~ s|([\{\}])|\\$1|g;
$self->{buff} .= qq{\$_handle->(q{$temp});};
}
}
@@ -276,7 +274,7 @@ sub pack {
}
if ($temp = $buff) {
- $temp =~ s|[\{\}\\]|\\$&|g;
+ $temp =~ s|([\{\}\\])|\\$1|g;
$self->{buff} .= qq{\$_handle->(q{$temp});};
}