lib/CPAN/lib/Locale/Maketext/Lexicon/Tie.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
package Locale::Maketext::Lexicon::Tie;
colas@0
     2
$Locale::Maketext::Lexicon::Tie::VERSION = '0.03';
colas@0
     3
colas@0
     4
use strict;
colas@0
     5
use Symbol ();
colas@0
     6
colas@0
     7
=head1 NAME
colas@0
     8
colas@0
     9
Locale::Maketext::Lexicon::Tie - Use tied hashes as lexicons for Maketext
colas@0
    10
colas@0
    11
=head1 SYNOPSIS
colas@0
    12
colas@0
    13
    package Hello::I18N;
colas@0
    14
    use base 'Locale::Maketext';
colas@0
    15
    use Locale::Maketext::Lexicon {
colas@0
    16
        en => [ Tie => [ DB_File => 'en.db' ] ],
colas@0
    17
    };
colas@0
    18
colas@0
    19
=head1 DESCRIPTION
colas@0
    20
colas@0
    21
This module lets you easily C<tie> the C<%Lexicon> hash to a database
colas@0
    22
or other data sources.  It takes an array reference of arguments, and
colas@0
    23
passes them directly to C<tie()>.
colas@0
    24
colas@0
    25
Entries will then be fetched whenever it is used; this module does not
colas@0
    26
cache them.
colas@0
    27
colas@0
    28
=cut
colas@0
    29
colas@0
    30
sub parse {
colas@0
    31
    my $self = shift;
colas@0
    32
    my $mod  = shift;
colas@0
    33
    my $sym  = Symbol::gensym();
colas@0
    34
colas@0
    35
    # Load the target module into memory
colas@0
    36
    {
colas@0
    37
        no strict 'refs';
colas@0
    38
        eval "use $mod; 1" or die $@ unless defined %{"$mod\::"};
colas@0
    39
    }
colas@0
    40
colas@0
    41
    # Perform the actual tie 
colas@0
    42
    tie %{*$sym}, $mod, @_;
colas@0
    43
colas@0
    44
    # Returns the GLOB reference, so %Lexicon will be tied too
colas@0
    45
    return $sym;
colas@0
    46
}
colas@0
    47
colas@0
    48
1;
colas@0
    49
colas@0
    50
=head1 SEE ALSO
colas@0
    51
colas@0
    52
L<Locale::Maketext>, L<Locale::Maketext::Lexicon>
colas@0
    53
colas@0
    54
=head1 AUTHORS
colas@0
    55
colas@0
    56
Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>
colas@0
    57
colas@0
    58
=head1 COPYRIGHT
colas@0
    59
colas@0
    60
Copyright 2002, 2003, 2004 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.
colas@0
    61
colas@0
    62
This program is free software; you can redistribute it and/or 
colas@0
    63
modify it under the same terms as Perl itself.
colas@0
    64
colas@0
    65
See L<http://www.perl.com/perl/misc/Artistic.html>
colas@0
    66
colas@0
    67
=cut