# HG changeset patch # User sergey # Date 1392845583 -14400 # Node ID 212cc86e470b8e0549958d70563c4a1b85fa8783 # Parent 2c14f66efa086c36373d125657b50e3581ede92f Code cleanup DateTime locale support for HTTP requests diff -r 2c14f66efa08 -r 212cc86e470b Lib/IMPL/Config.pm --- a/Lib/IMPL/Config.pm Tue Feb 18 18:17:20 2014 +0400 +++ b/Lib/IMPL/Config.pm Thu Feb 20 01:33:03 2014 +0400 @@ -1,9 +1,23 @@ package IMPL::Config; use strict; use warnings; +use mro; +use Carp qw(carp); + +use IMPL::lang qw(is); +use IMPL::Exception; use IMPL::Const qw(:access); use IMPL::declare { + require => { + PropertyInfo => 'IMPL::Class::PropertyInfo', + XmlFormatter => 'IMPL::Serialization::XmlFormatter', + Serializer => '-IMPL::Serializer', + Activator => '-IMPL::Config::Activator', + + Exception => 'IMPL::Exception', + IOException => '-IMPL::IOException' + }, base => [ 'IMPL::Object::Accessor' => undef, 'IMPL::Object::Serializable' => undef, @@ -13,12 +27,6 @@ use File::Spec(); -use IMPL::Class::Member; -use IMPL::Class::PropertyInfo; -use IMPL::Exception; - -use IMPL::Serialization; -use IMPL::Serialization::XmlFormatter; our $ConfigBase ||= ''; our $AppBase; @@ -28,14 +36,14 @@ my $class = ref $self || $self; - my $serializer = new IMPL::Serializer( - formatter => new IMPL::Serialization::XmlFormatter( + my $serializer = Serializer->new( + formatter => XmlFormatter->new( IdentOutput => 1, SkipWhitespace => 1 ) ); - open my $hFile,'<',$file or die new IMPL::Exception("Failed to open file",$file,$!); + open my $hFile,'<',$file or die IOException->new("Failed to open file",$file,$!); my $obj; eval { @@ -44,7 +52,7 @@ if ($@) { my $e=$@; - die new IMPL::Exception("Can't load the configuration file",$file,$e); + die Exception->new("Can't load the configuration file",$file,$e); } return $obj; } @@ -52,28 +60,28 @@ sub SaveXMLFile { my ($this,$file) = @_; - my $serializer = new IMPL::Serializer( - formatter => new IMPL::Serialization::XmlFormatter( + my $serializer = Serializer->new( + formatter => XmlFormatter->new( IdentOutput => 1, SkipWhitespace => 1 ) ); - open my $hFile,'>',$file or die new IMPL::Exception("Failed to open file",$file,$!); + open my $hFile,'>',$file or die IOException->new("Failed to open file",$file,$!); $serializer->Serialize($hFile, $this); } sub xml { my $this = shift; - my $serializer = new IMPL::Serializer( - formatter => new IMPL::Serialization::XmlFormatter( + my $serializer = Serializer->new( + formatter => XmlFormatter->new( IdentOutput => 1, SkipWhitespace => 1 ) ); my $str = ''; - open my $hFile,'>',\$str or die new IMPL::Exception("Failed to open stream",$!); + open my $hFile,'>',\$str or die IOException->new("Failed to open stream",$!); $serializer->Serialize($hFile, $this); @@ -88,7 +96,7 @@ my $val; $val = $this->rawGet($_) and $ctx->AddVar($_ => $val) foreach map $_->Name, $this->get_meta( - 'IMPL::Class::PropertyInfo', + PropertyInfo, sub { $_->access == ACCESS_PUBLIC and $_->setter; @@ -110,10 +118,10 @@ if (@_ == 1) { my $obj = $this->SUPER::get(@_); - return UNIVERSAL::isa($obj,'IMPL::Config::Activator') ? $obj->activate : $obj; + return is($obj,Activator) ? $obj->activate : $obj; } else { my @objs = $this->SUPER::get(@_); - return map UNIVERSAL::isa($_,'IMPL::Config::Activator') ? $_->activate : $_, @objs ; + return map is($_,Activator) ? $_->activate : $_, @objs ; } } @@ -127,15 +135,37 @@ } sub AppBase { + carp "obsolete"; + shift; + File::Spec->catdir($AppBase,@_); +} + +sub AppDir { shift; File::Spec->catdir($AppBase,@_); } +sub AppFile { + shift; + File::Spec->catfile($AppBase,@_); +} + sub ConfigBase { + carp "obsolete"; shift; File::Spec->catdir($ConfigBase,@_); } +sub ConfigDir { + shift; + File::Spec->catdir($ConfigBase,@_); +} + +sub ConfigFile { + shift; + File::Spec->catfile($ConfigBase,@_); +} + 1; __END__ diff -r 2c14f66efa08 -r 212cc86e470b Lib/IMPL/Config/Path.pm --- a/Lib/IMPL/Config/Path.pm Tue Feb 18 18:17:20 2014 +0400 +++ b/Lib/IMPL/Config/Path.pm Thu Feb 20 01:33:03 2014 +0400 @@ -15,8 +15,8 @@ my ($base,$path) = @$data; my %types = ( - appBase => 'AppBase', - configBase => 'ConfigBase' + appBase => 'AppDir', + configBase => 'ConfigDir' ); my $method = $types{$base}; diff -r 2c14f66efa08 -r 212cc86e470b Lib/IMPL/Web/Handler/LocaleHandler.pm --- a/Lib/IMPL/Web/Handler/LocaleHandler.pm Tue Feb 18 18:17:20 2014 +0400 +++ b/Lib/IMPL/Web/Handler/LocaleHandler.pm Thu Feb 20 01:33:03 2014 +0400 @@ -2,6 +2,7 @@ use strict; use IMPL::Const qw(:prop); +use DateTime; use IMPL::declare { require => { Resources => 'IMPL::Resources' @@ -56,7 +57,11 @@ $locale = $best->[0]; } - Resources->SetLocale($locale) if $locale; + if($locale) { + Resources->SetLocale($locale); + #$locale =~ tr/-/_/; + DateTime->DefaultLocale($locale); + } return $nextHandler->($action); } diff -r 2c14f66efa08 -r 212cc86e470b _test/temp.pl --- a/_test/temp.pl Tue Feb 18 18:17:20 2014 +0400 +++ b/_test/temp.pl Thu Feb 20 01:33:03 2014 +0400 @@ -1,5 +1,31 @@ #!/usr/bin/perl use strict; -use Scalar::Util qw(looks_like_number); -print looks_like_number(0); + +use Time::HiRes qw(gettimeofday tv_interval); + +my $hash = { + x => 2.0, + y => 2.0, + z => 2.3, + w => 1.0 +}; + +my $t = [gettimeofday]; +for(my $i = 0; $i < 1000000; $i ++) { + $hash->{x} = $i; +} + + +print "HASH: ",tv_interval($t,[gettimeofday]),"\n"; + + +my $array = [2,2,2.3,1.0]; + +$t = [gettimeofday]; + +for(my $i = 0; $i < 1000000; $i ++) { + $array->[1] = $i; +} + +print "ARRAY: ",tv_interval($t,[gettimeofday]),"\n"; \ No newline at end of file