Locale::Maketext::TieHash::nbsp - Tying subroutine to a hash
use strict; use Locale::Maketext::TieHash::nbsp; tie my %nbsp, 'Locale::Maketext::TieHash::nbsp', %config; # print: "15 pieces"; print $nbsp{15 pieces}; # If you want to test your Script, store you yours own test subroutine. # Substitute whitespace to a string which you see in the Browser. tied(%nbsp)->Config( sub => sub { (local $_ = $_[1]) =~ s/ /<span style="color:red">§</span>/g; }, );
my %config = tied(%nbsp)->Config();
my %config = tied(%nbsp)->Config(sub => sub{yourcode});
Subroutines don't have interpreted into strings. The module ties a subroutine to a hash. The Subroutine is executed at fetch hash. At long last this is the same, only the notation is shorter.
Sometimes the subroutine "sub" expects more than 1 parameter.
Then submit a reference on an array as hash key.
use Locale::Maketext::TieHash::nbsp; tie my %nbsp, 'Locale::Maketext::TieHash::nbsp';
"TIEHASH" ties your hash and set options defaults.
"Config" stores your own subroutine.
tied(%nbsp)->Config( sub => sub { # this sub is the default (local $_ = $_[0]) =~ s/ / /g; $_; }, );
The method calls croak, if the key of your hash is undef or your key isn't correct
and if the value, you set to key "sub", is not a reference of "CODE".
"Config" accepts all parameters as Hash and gives a Hash back with all attitudes.
Give your string as key of your hash.
"FETCH" will substitute the whitespace in " " and give it back as value.
# Substitute print $nbsp{$string};
"STORE" stores your own subroutine.
$nbsp{sub} = sub { # this sub is the default (local $_ = $_[0]) =~ s/ / /g; $_; };
The method calls croak, if the key of your hash is undef or your key isn't correct
and if the value, you set to key "sub", is not a reference of "CODE".
Tie::Hash
Locale::Maketext
Locale::Maketext::TieHash::L10N
Locale::Maketext::TieHash::quant
Steffen Winkler, <cpan@steffen-winkler.de>
Copyright (C) 2004, 2005 by Steffen Winkler
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.