lib/CPAN/lib/Locale/Maketext/Lexicon/Tie.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/CPAN/lib/Locale/Maketext/Lexicon/Tie.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +package Locale::Maketext::Lexicon::Tie;
     1.5 +$Locale::Maketext::Lexicon::Tie::VERSION = '0.03';
     1.6 +
     1.7 +use strict;
     1.8 +use Symbol ();
     1.9 +
    1.10 +=head1 NAME
    1.11 +
    1.12 +Locale::Maketext::Lexicon::Tie - Use tied hashes as lexicons for Maketext
    1.13 +
    1.14 +=head1 SYNOPSIS
    1.15 +
    1.16 +    package Hello::I18N;
    1.17 +    use base 'Locale::Maketext';
    1.18 +    use Locale::Maketext::Lexicon {
    1.19 +        en => [ Tie => [ DB_File => 'en.db' ] ],
    1.20 +    };
    1.21 +
    1.22 +=head1 DESCRIPTION
    1.23 +
    1.24 +This module lets you easily C<tie> the C<%Lexicon> hash to a database
    1.25 +or other data sources.  It takes an array reference of arguments, and
    1.26 +passes them directly to C<tie()>.
    1.27 +
    1.28 +Entries will then be fetched whenever it is used; this module does not
    1.29 +cache them.
    1.30 +
    1.31 +=cut
    1.32 +
    1.33 +sub parse {
    1.34 +    my $self = shift;
    1.35 +    my $mod  = shift;
    1.36 +    my $sym  = Symbol::gensym();
    1.37 +
    1.38 +    # Load the target module into memory
    1.39 +    {
    1.40 +        no strict 'refs';
    1.41 +        eval "use $mod; 1" or die $@ unless defined %{"$mod\::"};
    1.42 +    }
    1.43 +
    1.44 +    # Perform the actual tie 
    1.45 +    tie %{*$sym}, $mod, @_;
    1.46 +
    1.47 +    # Returns the GLOB reference, so %Lexicon will be tied too
    1.48 +    return $sym;
    1.49 +}
    1.50 +
    1.51 +1;
    1.52 +
    1.53 +=head1 SEE ALSO
    1.54 +
    1.55 +L<Locale::Maketext>, L<Locale::Maketext::Lexicon>
    1.56 +
    1.57 +=head1 AUTHORS
    1.58 +
    1.59 +Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>
    1.60 +
    1.61 +=head1 COPYRIGHT
    1.62 +
    1.63 +Copyright 2002, 2003, 2004 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.
    1.64 +
    1.65 +This program is free software; you can redistribute it and/or 
    1.66 +modify it under the same terms as Perl itself.
    1.67 +
    1.68 +See L<http://www.perl.com/perl/misc/Artistic.html>
    1.69 +
    1.70 +=cut