Locale::Maketext::TieHash::nbsp - Tying subroutine to a hash


NAME

Locale::Maketext::TieHash::nbsp - Tying subroutine to a hash


SYNOPSIS

 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;
   },
 );
 

read Configuration

 my %config = tied(%nbsp)->Config();

write Configuration

 my %config = tied(%nbsp)->Config(sub => sub{yourcode});


DESCRIPTION

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.


METHODS

TIEHASH

 use Locale::Maketext::TieHash::nbsp;
 tie my %nbsp, 'Locale::Maketext::TieHash::nbsp';

"TIEHASH" ties your hash and set options defaults.

Config

"Config" stores your own subroutine.

 tied(%nbsp)->Config(
   sub => sub {   # this sub is the default
     (local $_ = $_[0]) =~ s/ /&nbsp;/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.

FETCH

Give your string as key of your hash. "FETCH" will substitute the whitespace in "&nbsp;" and give it back as value.

 # Substitute
 print $nbsp{$string};

STORE (deprecated)

"STORE" stores your own subroutine.

 $nbsp{sub} = sub {   # this sub is the default
   (local $_ = $_[0]) =~ s/ /&nbsp;/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".


SEE ALSO

Tie::Hash

Locale::Maketext

Locale::Maketext::TieHash::L10N

Locale::Maketext::TieHash::quant


AUTHOR

Steffen Winkler, <cpan@steffen-winkler.de>


COPYRIGHT AND LICENSE

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.