CPAN-Search-Lite documentation

CPAN::Search::Lite::Lang - export some common data structures used by CPAN::Search::Lite::*

Code Index:


__top


NAME

CPAN::Search::Lite::Lang - export some common data structures used by CPAN::Search::Lite::*

__top


DESCRIPTION

This module can be used to populate some common data structures used by other CPAN::Search::Lite::* modules based on a requested language. The translated form of these structures are contained in CPAN::Search::Lite::Lang::*.pm (for example, en.pm or fr.pm). A hash %langs is exported, supplying a list of languages available, as well as a function load, used as

   load(lang => $lang, pages => $pages, chaps_desc => $chaps_desc);

which will, for example, take the data structure $pages and populate $pages-{$lang}> with the appropriate $page from the requested $pages from CPAN::Search::Lite::Lang::$lang.pm. At present the available data structures are:

__top


package CPAN::Search::Lite::Lang;
use strict;
use warnings;
our ($VERSION);
$VERSION = 0.66;

use utf8;
use base qw(Exporter);
our (@EXPORT_OK, %langs, $chaps_desc, $pages, $dslip, $months);
@EXPORT_OK = qw(%langs load);

%langs = map {$_ => 1} qw(de en es fr it pt);

sub load {
  my %args = @_;
  my $lang = delete $args{lang};
  unless ($lang) {
    return "Please specify a language";
  }
  unless ($langs{$lang}) {
    return "Language '$lang' not available";
  }
  my $pkg = __PACKAGE__ . '::' . $lang;
  eval "require $pkg";
  if ($@) {
    return "Error from requiring $pkg: $@";
  }
  eval "import $pkg qw(\$chaps_desc \$pages \$dslip \$months)";
  if ($@) {
    return "Error importing from $pkg: $@";
  }
  my %wanted = (chaps_desc => $chaps_desc,
                pages => $pages,
                dslip => $dslip,
                months => $months);
  foreach my $request (keys %args) {
    next unless (defined $request and defined $wanted{$request});
    $args{$request}->{$lang} = $wanted{$request};
  }
  return 1;
}

1;

__END__


CPAN-Search-Lite documentation