| 1 | # WWW:Auth::Template | ||
| 2 | # | ||
| 3 | # Copyright (c) 2002 Jonathan A. Waxman <jowaxman@law.upenn.edu> | ||
| 4 | # All rights reserved. | ||
| 5 | # | ||
| 6 | # This program is free software; you can redistribute it and/or | ||
| 7 | # modify it under the same terms as Perl itself. | ||
| 8 | |||
| 9 | |||
| 10 | package WWW::Auth::Template; | ||
| 11 | use base 'WWW::Auth::Base'; | ||
| 12 | |||
| 13 | |||
| 14 | use strict; | ||
| 15 | use WWW::Auth::Config; | ||
| 16 | |||
| 17 | |||
| 18 | sub _init { | ||
| 19 | my $self = shift; | ||
| 20 | my %params = @_; | ||
| 21 | |||
| 22 | return 1; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub process { | ||
| 26 | my $self = shift; | ||
| 27 | my ($template, $vars) = @_; | ||
| 28 | |||
| 29 | if (! open (TEMPLATE, $template)) { | ||
| 30 | return $self->error ("Error opening template $template: $!"); | ||
| 31 | } | ||
| 32 | my $text; | ||
| 33 | while (my $line = <TEMPLATE>) { | ||
| 34 | $line =~ s/\${([^}]+)}/$vars->{$1}/g; | ||
| 35 | $text .= $line; | ||
| 36 | } | ||
| 37 | close (TEMPLATE); | ||
| 38 | |||
| 39 | print $text; | ||
| 40 | |||
| 41 | return 1; | ||
| 42 | } | ||
| 43 | |||
| 44 | |||
| 45 | 1; |