/[bibulus]/bibulus/Lang/Lang.pm
ViewVC logotype

Diff of /bibulus/Lang/Lang.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by twid, Sun Jul 13 21:15:07 2003 UTC revision 1.2 by twid, Mon Jul 14 20:06:17 2003 UTC
# Line 1  Line 1 
1  package Bibulus::Lang;  package Bibulus::Lang;
2    
 use 5.008;  
 use strict;  
3  use warnings;  use warnings;
4  use Carp;  use Carp;
5    
6  use Bibulus::Lang::da;  # Accepted languages:
7  use Bibulus::Lang::en;  # [We don't want to put them into separate directories,
8    # so we just require them here.  It seems to work...]
9    require 'da.pm';
10    require 'en.pm';
11    # (Remember to add them as well in the 'lang' function!)
12    
13  sub new {  sub new {
14    my $class = shift;    my $class = shift;
# Line 22  sub lang { Line 24  sub lang {
24    my $self = shift;    my $self = shift;
25    if (@_) {    if (@_) {
26      my $l = shift;      my $l = shift;
27      $self->{LANG} = $l;      if ($l =~ /^(en|da)$/) {    # accepted languages
28      if ($l eq 'en') {        $self->{LANG} = $l;
       our @ISA = qw(Bibulus::Lang::en);  
     } elsif ($l eq 'da') {  
       our @ISA = qw(Bibulus::Lang::da);  
29      } else {      } else {
30        warn "Language $l unknown.\n";        warn "Language $l unknown.\n";
31      }      }
# Line 34  sub lang { Line 33  sub lang {
33    return $self->{LANG};    return $self->{LANG};
34  }  }
35    
36    # This is magic: Whenever a function in Bibulus::Lang is called
37    # that doesn't exist, this function will search for it in the
38    # relevant language module.
39    # E.g., if Bibulus::Lang::mastersthesis is called and
40    # $self->{LANG} eq 'da', then Bibulus::Lang::da:mastersthesis
41    # will be called instead (and that will presumably return 'speciale').
42    sub AUTOLOAD {
43      my ($self) = @_;
44      my $f = $AUTOLOAD;
45      $f =~ /DESTROY/ and return;   # to avoid error message
46      $f =~ s/(.*::)/$1$self->{LANG}\:\:/;
47      &$f(@_);
48    }
49    
50  1;  1;
51  __END__  __END__
52    
# Line 58  The following short program demonstrates Line 71  The following short program demonstrates
71   print $l->test, "\n";   print $l->test, "\n";
72   my $l2 = new Bibulus::Lang;   my $l2 = new Bibulus::Lang;
73   print $l2->test, "\n";   print $l2->test, "\n";
74     print $l->test, "\n";
75    
76    
77  All languages should provide the following functions:  All languages should provide the following functions:

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26