package Lingua::Translit::Tables; # # Copyright 2007-2008 by ... # Alex Linke, # Rona Linke, # # $Id: Tables.pm 159 2008-03-10 09:33:18Z alinke $ # use strict; use warnings; require 5.008; our $VERSION = '0.05'; use utf8; no bytes; use Carp; =pod =head1 NAME Lingua::Translit::Tables - provides transliteration tables =head1 SYNOPSIS use Lingua::Translit::Tables qw/:checks/; my $truth; $truth = translit_supported("ISO 9"); $truth = translit_reverse_supported("ISO 9"); use Lingua::Translit::Tables qw/:list/; translit_list_supported(); =head1 DESCRIPTION This module is primary used to provide transliteration tables for L and therefore allows to separate data and algorithm. Beyond that, it provides routines to check if a given transliteration is supported and allows to print a simple list of supported transliterations along with some meta information. =head1 EXPORTS No symbols are exported by default. Use either the routine's name or one of the following I to import symbols to your namespace. =over 4 =item B Import all routines. =item B Import all routines that allow to check if a given transliteration is supported: translit_supported() and translit_reverse_supported(). =item B Import translit_list_supported(). (Convenience tag) =back =cut require Exporter; our @ISA = qw/Exporter/; our @EXPORT = qw//; # Export nothing by default our @EXPORT_OK = qw/translit_supported translit_reverse_supported translit_list_supported/; our %EXPORT_TAGS = ( checks => [qw/translit_supported translit_reverse_supported/], list => [qw/translit_list_supported/], all => [@EXPORT_OK] ); # For convenience, the tables are initialized at the bottom of this file our %tables; # used internally to retrieve a reference to a single transliteration table sub _get_table_reference { my $name = shift(); foreach my $table (keys %tables) { return $tables{$table} if ($table =~ /^$name$/i); } return; } =head1 ROUTINES =head2 translit_supported(I) Returns true (1), iff I is supported. False (0) otherwise. =cut sub translit_supported { return (_get_table_reference($_[0]) ? 1 : 0); } =head2 translit_reverse_supported(I) Returns true (1), iff I is supported and allows reverse transliteration. False (0) otherwise. =cut sub translit_reverse_supported { my $table = _get_table_reference($_[0]); croak("Failed to retrieve table for $_[0].") unless ($table); return (($table->{reverse} =~ /^true$/) ? 1 : 0); } =head2 B Prints a list of all supported transliterations to STDOUT, providing the following information: * Name * Reversibility * Description The same information is provided in this document as well: =cut sub translit_list_supported { print "Transliterations supported by " . __PACKAGE__ . " v$VERSION:\n"; foreach my $table (keys %tables) { my $t = $tables{$table}; print "$t->{name}, reversible=$t->{reverse}, $t->{desc}\n"; } } =head1 SUPPORTED TRANSLITERATIONS =over 4 =item B, not reversible, C =item B, reversible, C =item B, not reversible, C =item B, not reversible, C =item B, not reversible, C =item B, not reversible, C =back =head1 EXTENDING If you want to extend the list of supported transliterations, have a look at the F directory within the distribution tarball. It contains XML definitions of transliteration tables and a template file F