und die restlichen .pm Module.
[kivitendo-erp.git] / SL / Iconv.pm
1 package SL::Iconv;
2
3 use Text::Iconv;
4
5 use SL::Common;
6
7 use vars qw(%converters);
8
9 use strict;
10
11 sub get_converter {
12   my ($from_charset, $to_charset) = @_;
13
14   my $index = "${from_charset}::${to_charset}";
15   if (!$converters{$index}) {
16     $converters{$index} = Text::Iconv->new($from_charset, $to_charset) || die;
17   }
18
19   return $converters{$index};
20 }
21
22 sub convert {
23   my ($from_charset, $to_charset, $text) = @_;
24
25   $from_charset ||= Common::DEFAULT_CHARSET;
26   $to_charset   ||= Common::DEFAULT_CHARSET;
27
28   my $converter = get_converter($from_charset, $to_charset);
29   return $converter->convert($text);
30 }
31
32 1;
33