Mercurial > pub > Impl
diff Lib/IMPL/Resources.pm @ 49:16ada169ca75
migrating to the Eclipse IDE
author | wizard@linux-odin.local |
---|---|
date | Fri, 26 Feb 2010 10:49:21 +0300 |
parents | 03e58a454b20 |
children | 1838bdb4d238 |
line wrap: on
line diff
--- a/Lib/IMPL/Resources.pm Fri Feb 26 01:43:42 2010 +0300 +++ b/Lib/IMPL/Resources.pm Fri Feb 26 10:49:21 2010 +0300 @@ -1,59 +1,59 @@ -package IMPL::Resources; -use strict; -use warnings; - -our $Encoding ||= 'utf-8'; -our %Files; - -my %Data; - - - foreach my $group (keys %Files) { - $Data{$group} = ParseResource($Files{$group}); - } - -sub findFile { - my ($fname) = @_; - - foreach my $dir (',',@INC) { - my $fullfname = "$dir/$fname"; - return $fullfname if -f $fullfname; - } - - return $fname; -} - -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; -} - -sub import { - my ($class,@groups) = @_; - my $caller = caller; - my %merged = map %{$Data{$_} || {} }, @groups; - - no strict 'refs'; - foreach my $item ( keys %merged ) { - *{"${caller}::ids_$item"} = sub { sprintf($merged{$item},@_) } - } -} - -1; +package IMPL::Resources; +use strict; +use warnings; + +our $Encoding ||= 'utf-8'; +our %Files; + +my %Data; + + + foreach my $group (keys %Files) { + $Data{$group} = ParseResource($Files{$group}); + } + +sub findFile { + my ($fname) = @_; + + foreach my $dir (',',@INC) { + my $fullfname = "$dir/$fname"; + return $fullfname if -f $fullfname; + } + + return $fname; +} + +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; +} + +sub import { + my ($class,@groups) = @_; + my $caller = caller; + my %merged = map %{$Data{$_} || {} }, @groups; + + no strict 'refs'; + foreach my $item ( keys %merged ) { + *{"${caller}::ids_$item"} = sub { sprintf($merged{$item},@_) } + } +} + +1;