App-MaMGal
view release on metacpan or search on metacpan
lib/App/MaMGal/Formatter.pm view on Meta::CPAN
{
my $self = shift;
my $le = shift;
$self->{locale_env} = $le;
}
sub HEADER
{
my $self = shift;
my $head = shift || '';
sprintf("<html><head><meta http-equiv='Content-Type' content='text/html; charset=%s'>%s</head><body>", $self->{locale_env}->get_charset, $head);
}
sub MAYBE_LINK
{
my $self = shift;
my $link = shift;
my $text = shift;
if ($link) {
$self->LINK($link.'.html', $text)
} else {
lib/App/MaMGal/LocaleEnv.pm view on Meta::CPAN
I18N::Langinfo->import(qw(langinfo CODESET));
};
if ($@) {
$logger->log_message("nl_langinfo(CODESET) is not available. ANSI_X3.4-1968 (a.k.a. US-ASCII) will be used as HTML encoding. $@");
$self->{get_codeset} = sub { "ANSI_X3.4-1968" };
} else {
$self->{get_codeset} = sub { langinfo(CODESET()) };
}
}
sub get_charset
{
my $self = shift;
&{$self->{get_codeset}}
}
sub set_locale
{
my $self = shift;
my $locale = shift;
setlocale(LC_ALL, $locale);
po/mamgal.pot view on Meta::CPAN
#
msgid ""
msgstr ""
"Project-Id-Version: mamgal 1.6\n"
"Report-Msgid-Bugs-To: Marcin Owsiany <marcin@owsiany.pl>\n"
"POT-Creation-Date: 2009-08-08 19:01+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: lib/App/MaMGal/EntryFactory.pm:71
#, perl-format
msgid "Internal Error: [%s] does not end with a base name."
msgstr ""
#. TRANSLATORS: This text will appear literally where no thumbnail is avaialable
#. for a given object.
#. Please use for whitespace, to avoid line breaks.
# This file is distributed under the same license as the mamgal package.
#
msgid ""
msgstr ""
"Project-Id-Version: mamgal 0.01\n"
"Report-Msgid-Bugs-To: Marcin Owsiany <marcin@owsiany.pl>\n"
"POT-Creation-Date: 2009-08-08 19:01+0100\n"
"PO-Revision-Date: 2008-12-10 18:18+0000\n"
"Last-Translator: Marcin Owsiany <marcin@owsiany.pl>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: lib/App/MaMGal/EntryFactory.pm:71
#, perl-format
msgid "Internal Error: [%s] does not end with a base name."
msgstr "BÅÄ
d wewnÄtrzny: [%s] nie koÅczy siÄ nazwÄ
bazowÄ
."
#. TRANSLATORS: This text will appear literally where no thumbnail is avaialable
#. for a given object.
#. Please use for whitespace, to avoid line breaks.
t/100_unit_formatter.t view on Meta::CPAN
use App::MaMGal::TestHelper;
prepare_test_data;
use_ok('App::MaMGal::Formatter');
my $f;
dies_ok(sub { App::MaMGal::Formatter->new }, "formatter cannot be created without parameters");
dies_ok(sub { App::MaMGal::Formatter->new(1) }, "formatter cannot be created with some junk parameter");
my $le = get_mock_localeenv;
$le->mock('get_charset', sub { 'UTF-8' });
$le->mock('format_time', sub { $_[1] == 1227684276 ? '12:00:00' : '13:13:13' });
$le->mock('format_date', sub { $_[1] == 1227684276 ? '18 gru 2004' : '2 kwi 2004' });
lives_ok(sub { $f = App::MaMGal::Formatter->new($le) }, "formatter can be created with locale env");
isa_ok($f, 'App::MaMGal::Formatter');
lives_ok(sub { $f->set_locale_env($le) }, "Formatter accepts a set_locale_env call");
my $mock_td = Test::MockObject->new
->mock('name', sub { 'td' })
->mock('is_root', sub { 1 });
my $d = Test::MockObject->new
->mock('elements', sub { () })
->mock('containers', sub { $mock_td })
->mock('name', sub { 'empty' })
->mock('is_root', sub { 0 });
dies_ok(sub { $f->format }, "dies with no args");
dies_ok(sub { $f->format(1) }, "dies with non-dir arg");
dies_ok(sub { $f->format($d, 1) }, "dies with more than one arg");
my $t;
lives_ok(sub { $t = $f->format($d) }, "formatter survives dir page creation");
tag_ok($t, 'meta', { 'http-equiv' => "Content-Type", 'content' => "text/html; charset=UTF-8" }, "generated dir page contains charset declaration");
no_tag($t, "img", {}, "the resulting page has no pics");
tag_ok($t, "td", { _content => App::MaMGal::Formatter->EMPTY_PAGE_TEXT },
"the resulting page has a cell");
link_ok($t, "../index.html", "the resulting page has a link down");
# Elements with the same description, testing description suppression.
my $mock_td2 = Test::MockObject->new
->mock('name', sub { 'td' })
->mock('is_root', sub { 1 });
my $e1 = get_mock_entry(undef, description => 'description 1');
t/100_unit_localeenv.t view on Meta::CPAN
prepare_test_data;
use_ok('App::MaMGal::LocaleEnv');
# test parameter checks
dies_ok(sub { App::MaMGal::LocaleEnv->new }, "Locale env dies on creation with no args");
dies_ok(sub { App::MaMGal::LocaleEnv->new(1) }, "Locale env dies on creation with junk arg");
my $le;
lives_ok(sub { $le = App::MaMGal::LocaleEnv->new(get_mock_logger) }, "new succeeds with logger");
my $ch;
lives_ok(sub { $ch = $le->get_charset }, "Locale env returns a charset");
ok($ch, "The charset returned by get_charset is never empty");
# It is not possible to portably test whether changing, retrieving or setting
# anything other than C locale is possible, because the set of available
# locales is system-specific.
lives_ok(sub { $le->set_locale("C") }, "Locale env can set a posix locale");
lives_ok(sub { $ch = $le->get_charset }, "Locale env can retrieve the charset name afterwards");
# The following string should be returned whether nl_langinfo is available or not
is($ch, "ANSI_X3.4-1968", "Charset name retrieved by locale env is expected name for posix locale");
# Time formatting
my ($t, $d);
lives_ok(sub { $t = $le->format_time(1227723614) }, "Locale env can format time");
lives_ok(sub { $d = $le->format_date(1227723614) }, "Locale env can format date");
# cannot test exact date and time, as it will differ depending on the timezone
like($t, qr'\d{2}:\d{2}:14', "Time is correct");
like($d, qr'11/2[567]/08', "Date is correct");
testlib/App/MaMGal/TestHelper.pm view on Meta::CPAN
my @methods = @_;
my $mf = Test::MockObject->new();
$mf->set_isa('App::MaMGal::Formatter');
$mf->mock($_, sub { "whatever" }) for @methods;
return $mf;
}
sub get_mock_localeenv {
my $ml = Test::MockObject->new();
$ml->set_isa('App::MaMGal::LocaleEnv');
$ml->mock('get_charset', sub { "ISO-8859-123" });
$ml->mock('set_locale');
$ml->mock('format_time', sub { "12:12:12" });
$ml->mock('format_date', sub { "18 dec 2004" });
return $ml;
}
sub get_mock_mplayer_wrapper {
my $mmw = Test::MockObject->new;
$mmw->set_isa('App::MaMGal::MplayerWrapper');
my $mock_image = Test::MockObject->new;
( run in 0.308 second using v1.01-cache-2.11-cpan-4d50c553e7e )