# HG changeset patch # User Sergey # Date 1265119789 -10800 # Node ID 75148ccd732de0cd7106910daa8c8f384ac495d9 # Parent 1b1fb9d54f55b234b680afdd40172cc0ab4e7568 Upgrading resources diff -r 1b1fb9d54f55 -r 75148ccd732d Lib/IMPL/Object/Singleton.pm --- a/Lib/IMPL/Object/Singleton.pm Fri Jan 29 16:19:31 2010 +0300 +++ b/Lib/IMPL/Object/Singleton.pm Tue Feb 02 17:09:49 2010 +0300 @@ -10,5 +10,38 @@ $instances{$self} || ($instances{$self} = $self->new(@_)); } +1; -1; +__END__ + +=pod + +=head1 SYNOPSIS + +package Foo; + +use base qw(IMPL::Object IMPL::Object::Singleton); + +#.... + +Foo->isnatnce->some_work(); + +Foo->isnatnce->get_result(); + +=head1 DESCRIPTION + +Реализует шаблон Singleton + +=head1 MEMBERS + +=head2 OPERATORS + +=list + +=item C + +Создает или возвращает экземпляр класса, если экземляр не существует, то он создается с параметрами C<@params>. + +=over + +=cut \ No newline at end of file diff -r 1b1fb9d54f55 -r 75148ccd732d Lib/IMPL/Resources/Strings.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Resources/Strings.pm Tue Feb 02 17:09:49 2010 +0300 @@ -0,0 +1,100 @@ +use strict; +use warnings; + +package IMPL::Resources::Strings::Storage; +package IMPL::Resources::Strings; +use File::Spec; + +our $Locale ||= 'default'; +our $Base ||='locale'; +our $Encoding ||= 'utf-8'; +our @Locations; + +@Locations = ('.') unless @Locations; + +sub import { + my ($self,$refStrings,%options) = @_; + + my ($class,$pathModule) = caller; + + my ($vol,$dir,$file) = File::Spec->splitpath($pathModule); + my $baseDir = File::Spec->catpath($vol,$dir,''); + + my @pathClass = split /::/,$class; + my $fileClass = pop @pathClass; + + my @ways = map { + my @path = ($_); + push @path,$Base; + push @path,$Locale; + + File::Spec->catfile(@path,@pathClass,$fileClass); + } @Locations; + + push @ways, File::Spec->catfile($baseDir,'locale',$Locale,$fileClass); + + + + my $stringsStorage = findResource(@Locations,$Base,$Locale,) + +} + +sub findResource { + my (@locations,$file,%options) = @_; + + +} + + + +sub parseResource { + my ($fname) = @_; + + open my $hRes, "<:encoding($Encoding)", findFile($fname) or die "Failed to open file $fname: $!"; + + my %Map; + my $line = 1; + while (<$hRes>) { + chomp; + $line ++ and next if /^\s*$/; + + if (/^(\w+)\s*=\s*(.*)$/) { + $Map{$1} = $2; + } else { + die "Invalid resource format in $fname at $line"; + } + $line ++; + } + + return \%Map; +} + +package IMPL::Resources::Strings::Storage; +use base qw(IMPL::Object); + +sub get { + my ($this,$msg_name) = @_; +} +1; + +__END__ + +=pod + +=head1 SYNOPSIS + +package Foo; + +use IMPL::Resources::Strings { + msg_say_hello => "Hello, %name!", + msg_module_name => "Simple Foo class" +}, auto => 1, locale => 'en-us'; + +sub InviteUser { + my ($this,$uname) = @_; + + print msg_say_hello(name => $uname); + +} + +=cut \ No newline at end of file