Hello community,
here is the log from the commit of package perl-Apache-LogFormat-Compiler for
openSUSE:Factory checked in at 2014-03-21 12:15:19
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Apache-LogFormat-Compiler (Old)
and /work/SRC/openSUSE:Factory/.perl-Apache-LogFormat-Compiler.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Apache-LogFormat-Compiler"
Changes:
--------
---
/work/SRC/openSUSE:Factory/perl-Apache-LogFormat-Compiler/perl-Apache-LogFormat-Compiler.changes
2013-07-09 20:55:21.000000000 +0200
+++
/work/SRC/openSUSE:Factory/.perl-Apache-LogFormat-Compiler.new/perl-Apache-LogFormat-Compiler.changes
2014-03-21 12:15:20.000000000 +0100
@@ -1,0 +2,21 @@
+Tue Mar 18 07:52:42 UTC 2014 - [email protected]
+
+- buildrequire timezone for testsuite
+
+-------------------------------------------------------------------
+Fri Mar 7 06:51:23 UTC 2014 - [email protected]
+
+- updated to 0.30
+ - add docs abount POSIX::strftime::Compiler
+ - non trial release
+ - [TRIAL] switch to using POSIX::strftime::Compiler
+ - fixed POSIX::setlocale fails on system without locales (Android) #6
(Thank you dex4er)
+ - skip tz test on Windows.
+ - requires perl v5.8.4 (Thank you dex4er)
+ - skip tz test on Cygwin.
+ - Fixed test. Cygwin does not die tzset. But timezone does not been changed
+ - Fixed test. POSIX::tzset not implemented on Windows (Thank you dex4er)
+ - Check tzoffset for every line. It's need for daylight saving time.
+ - Use POSIX::strftime::GNU if available (Thank you dex4er)
+
+-------------------------------------------------------------------
Old:
----
Apache-LogFormat-Compiler-0.13.tar.gz
New:
----
Apache-LogFormat-Compiler-0.30.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Apache-LogFormat-Compiler.spec ++++++
--- /var/tmp/diff_new_pack.lkLdxf/_old 2014-03-21 12:15:20.000000000 +0100
+++ /var/tmp/diff_new_pack.lkLdxf/_new 2014-03-21 12:15:20.000000000 +0100
@@ -1,7 +1,7 @@
#
# spec file for package perl-Apache-LogFormat-Compiler
#
-# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -17,7 +17,7 @@
Name: perl-Apache-LogFormat-Compiler
-Version: 0.13
+Version: 0.30
Release: 0
%define cpan_name Apache-LogFormat-Compiler
Summary: Compile a log format string to perl-code
@@ -33,16 +33,16 @@
BuildRequires: perl(CPAN::Meta::Prereqs)
BuildRequires: perl(HTTP::Request::Common)
BuildRequires: perl(Module::Build) >= 0.38
+BuildRequires: perl(POSIX::strftime::Compiler) >= 0.30
+BuildRequires: perl(Test::MockTime)
BuildRequires: perl(Test::More) >= 0.98
BuildRequires: perl(Test::Requires)
BuildRequires: perl(Try::Tiny) >= 0.12
BuildRequires: perl(URI::Escape) >= 1.60
-#BuildRequires: perl(Apache::LogFormat::Compiler)
-#BuildRequires: perl(HTTP::Message::PSGI)
-#BuildRequires: perl(Plack::Builder)
-#BuildRequires: perl(Plack::Test)
-#BuildRequires: perl(t::Req2PSGI)
+Requires: perl(POSIX::strftime::Compiler) >= 0.30
%{perl_requires}
+# MANUAL
+BuildRequires: timezone
%description
Compile a log format string to perl-code. For faster generation of
++++++ Apache-LogFormat-Compiler-0.13.tar.gz ->
Apache-LogFormat-Compiler-0.30.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/Build.PL
new/Apache-LogFormat-Compiler-0.30/Build.PL
--- old/Apache-LogFormat-Compiler-0.13/Build.PL 2013-05-24 02:19:38.000000000
+0200
+++ new/Apache-LogFormat-Compiler-0.30/Build.PL 2014-01-28 08:59:10.000000000
+0100
@@ -25,12 +25,16 @@
name => 'Apache-LogFormat-Compiler',
module_name => 'Apache::LogFormat::Compiler',
- allow_pure_perl => 0,
+ allow_pureperl => 0,
script_files => [glob('script/*'), glob('bin/*')],
+ c_source => [qw()],
+ PL_files => {},
test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt')
? 't/ xt/' : 't/',
recursive_test_files => 1,
+
+
);
if (-d 'share') {
$args{share_dir} = 'share';
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/Changes
new/Apache-LogFormat-Compiler-0.30/Changes
--- old/Apache-LogFormat-Compiler-0.13/Changes 2013-05-24 02:19:38.000000000
+0200
+++ new/Apache-LogFormat-Compiler-0.30/Changes 2014-01-28 08:59:10.000000000
+0100
@@ -1,5 +1,40 @@
Revision history for Perl extension Apache::LogFormat::Compiler
+0.30 2014-01-28T07:59:07Z
+
+ - add docs abount POSIX::strftime::Compiler
+ - non trial release
+
+0.24 2014-01-27T03:12:16Z
+
+ - [TRIAL] switch to using POSIX::strftime::Compiler
+
+0.23 2014-01-16T15:53:09Z
+
+ - fixed POSIX::setlocale fails on system without locales (Android) #6
(Thank you dex4er)
+
+0.22 2014-01-08T00:25:14Z
+
+ - skip tz test on Windows.
+
+0.21 2014-01-07T13:43:29Z
+
+ - requires perl v5.8.4 (Thank you dex4er)
+ - skip tz test on Cygwin.
+
+0.20 2014-01-07T00:38:29Z
+
+ - Fixed test. Cygwin does not die tzset. But timezone does not been changed
+
+0.15 2014-01-06T13:47:11Z
+
+ - Fixed test. POSIX::tzset not implemented on Windows (Thank you dex4er)
+
+0.14 2014-01-06T05:41:14Z
+
+ - Check tzoffset for every line. It's need for daylight saving time.
+ - Use POSIX::strftime::GNU if available (Thank you dex4er)
+
0.13 2013-05-24T00:19:31Z
- fixed pod issue (Thank you fschlich)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/MANIFEST
new/Apache-LogFormat-Compiler-0.30/MANIFEST
--- old/Apache-LogFormat-Compiler-0.13/MANIFEST 2013-05-24 02:19:38.000000000
+0200
+++ new/Apache-LogFormat-Compiler-0.30/MANIFEST 2014-01-28 08:59:10.000000000
+0100
@@ -10,6 +10,7 @@
t/01_basic.t
t/02_custom.t
t/03_extra.t
+t/04_tz.t
t/Req2PSGI.pm
META.yml
MANIFEST
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/META.json
new/Apache-LogFormat-Compiler-0.30/META.json
--- old/Apache-LogFormat-Compiler-0.13/META.json 2013-05-24
02:19:38.000000000 +0200
+++ new/Apache-LogFormat-Compiler-0.30/META.json 2014-01-28
08:59:10.000000000 +0100
@@ -4,8 +4,10 @@
"Masahiro Nagano <[email protected]>"
],
"dynamic_config" : 0,
- "generated_by" : "Minilla/v0.4.2",
- "license" : "perl_5",
+ "generated_by" : "Minilla/v0.11.0",
+ "license" : [
+ "perl_5"
+ ],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
@@ -19,7 +21,8 @@
"share",
"eg",
"examples",
- "author"
+ "author",
+ "builder"
]
},
"prereqs" : {
@@ -35,19 +38,21 @@
"Test::CPAN::Meta" : "0",
"Test::MinimumVersion" : "0.10108",
"Test::Pod" : "1.41",
- "Test::Spellunker" : "v0.2.2"
+ "Test::Spellunker" : "v0.2.7"
}
},
"runtime" : {
"requires" : {
"POSIX" : "0",
+ "POSIX::strftime::Compiler" : "0.30",
"Time::Local" : "0",
- "perl" : "5.008005"
+ "perl" : "5.008004"
}
},
"test" : {
"requires" : {
"HTTP::Request::Common" : "0",
+ "Test::MockTime" : "0",
"Test::More" : "0.98",
"Test::Requires" : "0",
"Try::Tiny" : "0.12",
@@ -58,7 +63,7 @@
"provides" : {
"Apache::LogFormat::Compiler" : {
"file" : "lib/Apache/LogFormat/Compiler.pm",
- "version" : "0.13"
+ "version" : "0.30"
}
},
"release_status" : "stable",
@@ -72,8 +77,9 @@
"web" : "https://github.com/kazeburo/Apache-LogFormat-Compiler"
}
},
- "version" : "0.13",
+ "version" : "0.30",
"x_contributors" : [
- "Florian Schlichting <[email protected]>"
+ "Florian Schlichting <[email protected]>",
+ "Piotr Roszatycki <[email protected]>"
]
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/META.yml
new/Apache-LogFormat-Compiler-0.30/META.yml
--- old/Apache-LogFormat-Compiler-0.13/META.yml 2013-05-24 02:19:38.000000000
+0200
+++ new/Apache-LogFormat-Compiler-0.30/META.yml 2014-01-28 08:59:10.000000000
+0100
@@ -4,6 +4,7 @@
- 'Masahiro Nagano <[email protected]>'
build_requires:
HTTP::Request::Common: 0
+ Test::MockTime: 0
Test::More: 0.98
Test::Requires: 0
Try::Tiny: 0.12
@@ -13,7 +14,7 @@
CPAN::Meta::Prereqs: 0
Module::Build: 0.38
dynamic_config: 0
-generated_by: 'Minilla/v0.4.2, CPAN::Meta::Converter version 2.130880'
+generated_by: 'Minilla/v0.11.0, CPAN::Meta::Converter version 2.132830'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -28,18 +29,21 @@
- eg
- examples
- author
+ - builder
provides:
Apache::LogFormat::Compiler:
file: lib/Apache/LogFormat/Compiler.pm
- version: 0.13
+ version: 0.30
requires:
POSIX: 0
+ POSIX::strftime::Compiler: 0.30
Time::Local: 0
- perl: 5.008005
+ perl: 5.008004
resources:
bugtracker: https://github.com/kazeburo/Apache-LogFormat-Compiler/issues
homepage: https://github.com/kazeburo/Apache-LogFormat-Compiler
repository: git://github.com/kazeburo/Apache-LogFormat-Compiler.git
-version: 0.13
+version: 0.30
x_contributors:
- 'Florian Schlichting <[email protected]>'
+ - 'Piotr Roszatycki <[email protected]>'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/README.md
new/Apache-LogFormat-Compiler-0.30/README.md
--- old/Apache-LogFormat-Compiler-0.13/README.md 2013-05-24
02:19:38.000000000 +0200
+++ new/Apache-LogFormat-Compiler-0.30/README.md 2014-01-28
08:59:10.000000000 +0100
@@ -87,6 +87,10 @@
$app
};
+# ABOUT POSIX::strftime::Compiler
+
+This module uses
[POSIX::strftime::Compiler](http://search.cpan.org/perldoc?POSIX::strftime::Compiler)
for generate datetime string. POSIX::strftime::Compiler provides GNU C library
compatible strftime(3). But this module will not affected by the system locale.
This feature is useful when you want to write loggers, servers and portable
applications.
+
# ADD CUSTOM FORMAT STRING
Apache::LogFormat::Compiler allows one to add a custom format string
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/cpanfile
new/Apache-LogFormat-Compiler-0.30/cpanfile
--- old/Apache-LogFormat-Compiler-0.13/cpanfile 2013-05-24 02:19:38.000000000
+0200
+++ new/Apache-LogFormat-Compiler-0.30/cpanfile 2014-01-28 08:59:10.000000000
+0100
@@ -1,6 +1,7 @@
requires 'POSIX';
requires 'Time::Local';
-requires 'perl', '5.008005';
+requires 'perl', '5.008004';
+requires 'POSIX::strftime::Compiler', '0.30';
on test => sub {
requires 'HTTP::Request::Common';
@@ -8,4 +9,5 @@
requires 'Test::Requires';
requires 'Try::Tiny', '0.12';
requires 'URI::Escape', '1.60';
+ requires 'Test::MockTime';
};
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/eg/logbench.pl
new/Apache-LogFormat-Compiler-0.30/eg/logbench.pl
--- old/Apache-LogFormat-Compiler-0.13/eg/logbench.pl 2013-05-24
02:19:38.000000000 +0200
+++ new/Apache-LogFormat-Compiler-0.30/eg/logbench.pl 2014-01-28
08:59:10.000000000 +0100
@@ -1,49 +1,48 @@
-#!/usr/bin/env perl
-
use strict;
-use warnings;
+use Benchmark qw/ :all /;
+use File::Temp qw/ tempfile /;
+use Storable qw/ nstore retrieve /;
use HTTP::Request::Common;
-use HTTP::Message::PSGI;
-use Plack::Test;
-use Plack::Builder;
-use Apache::LogFormat::Compiler;
-use Benchmark qw/cmpthese timethese/;
-
-my $log_app = builder {
- enable 'AccessLog', format => "combined";
- sub{ [ 200, [], [ "Hello "] ] };
-};
-my $log_handler = Apache::LogFormat::Compiler->new();
-my $compile_log_app = builder {
- enable sub {
- my $app = shift;
- sub {
- my $env = shift;
- my $res = $app->();
- warn $log_handler->log_line($env,$res,6,0);
- }
- };
- sub{ [ 200, [], [ "Hello "] ] };
-};
-my $env = req_to_psgi(GET "/");
-open(STDERR,'>','/dev/null');
+my $result = {};
+for my $name (qw! extlib-1.0022/lib/perl5 lib !) {
+ my ($fh, $fn) = tempfile();
+ my $pid = fork;
+ if ($pid) {
+ close $fh;
+ wait;
+ }
+ else {
+ eval qq{use lib '$name'};
+ require Plack;
+ use Plack::Builder;
+
+ warn $Plack::VERSION;
+ my $log_app = builder {
+ enable 'AccessLog', format => "combined", logger => sub {};
+ sub{ [ 200, [], [ "Hello"] ] };
+ };
+
+ my $code = sub {
+
$log_app->({REQUEST_METHOD=>"GET",SERVER_PROTOCOL=>"HTTP/1.0",REQUEST_URI=>"/"});
+ };
+
+ my $r = timethis(0, $code);
+ nstore $r, $fn;
+ exit;
+ }
+ $result->{$name} = retrieve $fn;
+};
-cmpthese(timethese(0,{
- 'log' => sub {
- $log_app->($env);
- },
- 'compilelog' => sub {
- $compile_log_app->($env);
- },
-}));
+cmpthese $result;
__END__
-Benchmark: running compilelog, log for at least 3 CPU seconds...
-compilelog: 3 wallclock secs ( 3.03 usr + 0.19 sys = 3.22 CPU) @ 25447.20/s
(n=81940)
- log: 3 wallclock secs ( 3.17 usr + 0.01 sys = 3.18 CPU) @ 3226.73/s
(n=10261)
- Rate log compilelog
-log 3227/s -- -87%
-compilelog 25447/s 689% --
+1.0022 at eg/logbench.pl line 21.
+timethis for 3: 3 wallclock secs ( 3.17 usr + 0.00 sys = 3.17 CPU) @
8828.71/s (n=27987)
+1.0030 at eg/logbench.pl line 21.
+timethis for 3: 3 wallclock secs ( 3.28 usr + 0.00 sys = 3.28 CPU) @
50064.02/s (n=164210)
+ Rate extlib-1.0022/lib/perl5 lib
+extlib-1.0022/lib/perl5 8829/s -- -82%
+lib 50064/s 467% --
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/Apache-LogFormat-Compiler-0.13/lib/Apache/LogFormat/Compiler.pm
new/Apache-LogFormat-Compiler-0.30/lib/Apache/LogFormat/Compiler.pm
--- old/Apache-LogFormat-Compiler-0.13/lib/Apache/LogFormat/Compiler.pm
2013-05-24 02:19:38.000000000 +0200
+++ new/Apache-LogFormat-Compiler-0.30/lib/Apache/LogFormat/Compiler.pm
2014-01-28 08:59:10.000000000 +0100
@@ -2,12 +2,18 @@
use strict;
use warnings;
-use 5.008005;
+use 5.008004;
use Carp;
-use POSIX ();
-use Time::Local qw//;
+use POSIX::strftime::Compiler qw//;
+use constant {
+ ENVS => 0,
+ RES => 1,
+ LENGTH => 2,
+ REQTIME => 3,
+ TIME => 4,
+};
-our $VERSION = '0.13';
+our $VERSION = '0.30';
# copy from Plack::Middleware::AccessLog
our %formats = (
@@ -15,24 +21,6 @@
combined => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"',
);
-my $tzoffset = POSIX::strftime("%z", localtime);
-if ( $tzoffset !~ /^[+-]\d{4}$/ ) {
- my @t = localtime(time);
- my $s = Time::Local::timegm(@t) - Time::Local::timelocal(@t);
- my $min_offset = int($s / 60);
- $tzoffset = sprintf '%+03d%02u', $min_offset / 60, $min_offset % 60;
-}
-
-sub _strftime {
- my ($fmt, @time) = @_;
- $fmt =~ s/%z/$tzoffset/g if $tzoffset;
- my $old_locale = POSIX::setlocale(&POSIX::LC_ALL);
- POSIX::setlocale(&POSIX::LC_ALL, 'C');
- my $out = POSIX::strftime($fmt, @time);
- POSIX::setlocale(&POSIX::LC_ALL, $old_locale);
- return $out;
-};
-
sub _safe {
my $string = shift;
return unless defined $string;
@@ -44,7 +32,8 @@
my $string = shift;
return '-' if ! defined $string;
return '-' if ! length $string;
- _safe($string);
+ $string =~ s/([^[:print:]])/"\\x" . unpack("H*", $1)/eg;
+ return $string;
}
sub header_get {
@@ -64,19 +53,19 @@
my $psgi_reserved = { CONTENT_LENGTH => 1, CONTENT_TYPE => 1 };
my $block_handler = sub {
- my($self,$block, $type) = @_;
+ my($block, $type, $extra) = @_;
my $cb;
if ($type eq 'i') {
$block =~ s/-/_/g;
$block = uc($block);
$block = "HTTP_${block}" unless $psgi_reserved->{$block};
- $cb = q!_string($env->{'!.$block.q!'})!;
+ $cb = q!_string($_[ENVS]->{'!.$block.q!'})!;
} elsif ($type eq 'o') {
- $cb = q!_string(header_get($res->[1],'!.$block.q!'))!;
+ $cb = q!_string(header_get($_[RES]->[1],'!.$block.q!'))!;
} elsif ($type eq 't') {
- $cb = q!"[" . _strftime('!.$block.q!', localtime($time)) . "]"!;
- } elsif (exists $self->{extra_block_handlers}->{$type}) {
- $cb =
q!_string($extra_block_handlers->{'!.$type.q!'}->('!.$block.q!',$env,$res,$length,$reqtime))!;
+ $cb = q!"[" . POSIX::strftime::Compiler::strftime('!.$block.q!', @lt)
. "]"!;
+ } elsif (exists $extra->{$type}) {
+ $cb =
q!_string($extra_block_handlers->{'!.$type.q!'}->('!.$block.q!',$_[ENVS],$_[RES],$_[LENGTH],$_[REQTIME]))!;
} else {
Carp::croak("{$block}$type not supported");
$cb = "-";
@@ -87,33 +76,32 @@
our %char_handler = (
'%' => q!'%'!,
- h => q!($env->{REMOTE_ADDR} || '-')!,
+ h => q!($_[ENVS]->{REMOTE_ADDR} || '-')!,
l => q!'-'!,
- u => q!($env->{REMOTE_USER} || '-')!,
- t => q!"[" . $t . "]"!,
- r => q!_safe($env->{REQUEST_METHOD}) . " " . _safe($env->{REQUEST_URI}) .
- " " . $env->{SERVER_PROTOCOL}!,
- s => q!$res->[0]!,
- b => q!(defined $length ? $length : '-')!,
- T => q!(defined $reqtime ? int($reqtime*1_000_000) : '-')!,
- D => q!(defined $reqtime ? $reqtime : '-')!,
- v => q!($env->{SERVER_NAME} || '-')!,
- V => q!($env->{HTTP_HOST} || $env->{SERVER_NAME} || '-')!,
- p => q!$env->{SERVER_PORT}!,
+ u => q!($_[ENVS]->{REMOTE_USER} || '-')!,
+ t => q!'[' . $t . ']'!,
+ r => q!_safe($_[ENVS]->{REQUEST_METHOD}) . " " .
_safe($_[ENVS]->{REQUEST_URI}) .
+ " " . $_[ENVS]->{SERVER_PROTOCOL}!,
+ s => q!$_[RES]->[0]!,
+ b => q!(defined $_[LENGTH] ? $_[LENGTH] : '-')!,
+ T => q!(defined $_[REQTIME] ? int($_[REQTIME]*1_000_000) : '-')!,
+ D => q!(defined $_[REQTIME] ? $_[REQTIME] : '-')!,
+ v => q!($_[ENVS]->{SERVER_NAME} || '-')!,
+ V => q!($_[ENVS]->{HTTP_HOST} || $_[ENVS]->{SERVER_NAME} || '-')!,
+ p => q!$_[ENVS]->{SERVER_PORT}!,
P => q!$$!,
- m => q!_safe($env->{REQUEST_METHOD})!,
- U => q!_safe($env->{PATH_INFO})!,
- q => q!(($env->{QUERY_STRING} ne '') ? '?' . _safe($env->{QUERY_STRING}) :
'' )!,
- H => q!$env->{SERVER_PROTOCOL}!,
+ m => q!_safe($_[ENVS]->{REQUEST_METHOD})!,
+ U => q!_safe($_[ENVS]->{PATH_INFO})!,
+ q => q!(($_[ENVS]->{QUERY_STRING} ne '') ? '?' .
_safe($_[ENVS]->{QUERY_STRING}) : '' )!,
+ H => q!$_[ENVS]->{SERVER_PROTOCOL}!,
);
my $char_handler = sub {
- my $self = shift;
- my $char = shift;
+ my ($char, $extra) = @_;
my $cb = $char_handler{$char};
- if (!$cb && exists $self->{extra_char_handlers}->{$char}) {
- $cb =
q!_string($extra_char_handlers->{'!.$char.q!'}->($env,$res,$length,$reqtime))!;
+ if (!$cb && exists $extra->{$char}) {
+ $cb =
q!_string($extra_char_handlers->{'!.$char.q!'}->($_[ENVS],$_[RES],$_[LENGTH],$_[REQTIME]))!;
}
unless ($cb) {
Carp::croak "\%$char not supported.";
@@ -131,47 +119,53 @@
my %opts = @_;
- my $self = bless {
- fmt => $fmt,
- extra_block_handlers => $opts{block_handlers} || {},
- extra_char_handlers => $opts{char_handlers} || {},
- }, $class;
- $self->compile();
- return $self;
+ my ($code_ref, $code) = compile($fmt, $opts{block_handlers} || {},
$opts{char_handlers} || {});
+ bless [$code_ref, $code], $class;
}
sub compile {
- my $self = shift;
- my $fmt = $self->{fmt};
+ my $fmt = shift;
+ my $extra_block_handlers = shift;
+ my $extra_char_handlers = shift;
$fmt =~ s/!/\\!/g;
$fmt =~ s!
(?:
\%\{(.+?)\}([a-zA-Z]) |
\%(?:[<>])?([a-zA-Z\%])
)
- ! $1 ? $block_handler->($self, $1, $2) : $char_handler->($self, $3) !egx;
-
+ ! $1 ? $block_handler->($1, $2, $extra_block_handlers) :
$char_handler->($3, $extra_char_handlers) !egx;
+
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
- my $tz = $tzoffset;
- my $extra_block_handlers = $self->{extra_block_handlers};
- my $extra_char_handlers = $self->{extra_char_handlers};
+ my $c = {};
$fmt = q~sub {
- my ($env,$res,$length,$reqtime,$time) = @_;
- $time = time() if ! defined $time;
- my @lt = localtime($time);;
- my $t = sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $lt[3],
$abbr[$lt[4]], $lt[5]+1900,
- $lt[2], $lt[1], $lt[0], $tz;
+ $_[TIME] = time() if ! defined $_[TIME];
+ my @lt = localtime($_[TIME]);
+ if ( ! exists $c->{tz_cache} || ! exists $c->{isdst_cache} || $lt[8]
!= $c->{isdst_cache} ) {
+ $c->{tz_cache} = POSIX::strftime::Compiler::strftime('%z',@lt);
+ $c->{isdst_cache} = $lt[8];
+ }
+ my $t = sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $lt[3],
$abbr[$lt[4]], $lt[5]+1900,
+ $lt[2], $lt[1], $lt[0], $c->{tz_cache};
q!~ . $fmt . q~!
}~;
- $self->{log_handler_code} = $fmt;
- $self->{log_handler} = eval $fmt; ## no critic
+ my $code_ref = eval $fmt; ## no critic
+ die $@ . "\n===\n" . $fmt if $@;
+ wantarray ? ($code_ref, $fmt) : $code_ref;
}
sub log_line {
my $self = shift;
- my ($env,$res,$length,$reqtime,$time) = @_;
- my $log = $self->{log_handler}->($env,$res,$length,$reqtime,$time);
- $log . "\n";
+ $self->[0]->(@_) . "\n";
+}
+
+sub code {
+ my $self = shift;
+ $self->[1];
+}
+
+sub code_ref {
+ my $self = shift;
+ $self->[0];
}
1;
@@ -272,6 +266,10 @@
=back
+=head1 ABOUT POSIX::strftime::Compiler
+
+This module uses L<POSIX::strftime::Compiler> for generate datetime string.
POSIX::strftime::Compiler provides GNU C library compatible strftime(3). But
this module will not affected by the system locale. This feature is useful when
you want to write loggers, servers and portable applications.
+
=head1 ADD CUSTOM FORMAT STRING
Apache::LogFormat::Compiler allows one to add a custom format string
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Apache-LogFormat-Compiler-0.13/t/04_tz.t
new/Apache-LogFormat-Compiler-0.30/t/04_tz.t
--- old/Apache-LogFormat-Compiler-0.13/t/04_tz.t 1970-01-01
01:00:00.000000000 +0100
+++ new/Apache-LogFormat-Compiler-0.30/t/04_tz.t 2014-01-28
08:59:10.000000000 +0100
@@ -0,0 +1,83 @@
+use strict;
+use warnings;
+use Test::More;
+use POSIX;
+use Time::Local;
+use Test::MockTime qw/set_fixed_time restore_time/;
+use t::Req2PSGI;
+use Apache::LogFormat::Compiler;
+use HTTP::Request::Common;
+
+sub time_difference {
+ my $now = time();
+ timegm(localtime($now)) - $now;
+}
+
+eval {
+ POSIX::tzset;
+ die q!tzset is implemented on this Cygwin. But Windows can't change tz
inside script! if $^O eq 'cygwin';
+ die q!tzset is implemented on this Windows. But Windows can't change tz
inside script! if $^O eq 'MSWin32';
+};
+if ( $@ ) {
+ plan skip_all => $@;
+}
+
+my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
+my @timezones = (
+ ['Australia/Darwin','+0930','+0930','+0930','+0930' ],
+ ['Asia/Tokyo', '+0900','+0900','+0900','+0900'],
+ ['UTC', '+0000','+0000','+0000','+0000'],
+ ['Europe/London', '+0000','+0100','+0100','+0000'],
+ ['America/New_York','-0500', '-0400', '-0400', '-0500']
+);
+
+for my $timezones (@timezones) {
+ my ($timezone, @tz) = @$timezones;
+ local $ENV{TZ} = $timezone;
+ POSIX::tzset;
+ my $log_handler = Apache::LogFormat::Compiler->new('%t');
+
+ subtest "$timezone" => sub {
+ my $i=0;
+ for my $date ( ([10,1,2013], [10,5,2013], [15,8,2013], [15,11,2013]) )
{
+ my ($day,$month,$year) = @$date;
+
+ set_fixed_time(timelocal(0, 45, 12, $day, $month - 1, $year));
+ my $tz = $tz[$i];
+
+ my $log = $log_handler->log_line(
+ t::Req2PSGI::req_to_psgi(GET "/"),
+ [200,[],[q!OK!]],
+ );
+
+ my $month_name = $abbr[$month-1];
+ is $log, "[$day/$month_name/2013:12:45:00 $tz]\n","$timezone
$year/$month/$day";
+ $i++;
+ }
+ };
+
+ my $log_handler2 = Apache::LogFormat::Compiler->new('%{%z}t');
+ subtest "$timezone custom format" => sub {
+ my $i=0;
+ for my $date ( ([10,1,2013], [10,5,2013], [15,8,2013], [15,11,2013]) )
{
+ my ($day,$month,$year) = @$date;
+
+ set_fixed_time(timelocal(0, 45, 12, $day, $month - 1, $year));
+ my $tz = $tz[$i];
+
+ my $log = $log_handler2->log_line(
+ t::Req2PSGI::req_to_psgi(GET "/"),
+ [200,[],[q!OK!]],
+ );
+
+ my $month_name = $abbr[$month-1];
+ is $log, "[$tz]\n","custom format: $timezone $year/$month/$day";
+ $i++;
+ }
+ };
+
+
+}
+
+done_testing();
+
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]