Mercurial > pub > Impl
diff Lib/IMPL/Config.pm @ 395:212cc86e470b
Code cleanup
DateTime locale support for HTTP requests
author | sergey |
---|---|
date | Thu, 20 Feb 2014 01:33:03 +0400 |
parents | 4ddb27ff4a0b |
children |
line wrap: on
line diff
--- 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__