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


Back to Top


NAME

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

Back to Top


VERSION

1.02

Back to Top


SYNOPSIS

    use strict;
    use warnings;
    use Locale::Maketext::TieHash::nbsp;

without a special configuration (using entities)

    tie my %nbsp, 'Locale::Maketext::TieHash::nbsp';
    print $nbsp{'15 pieces'};
    # result: '15 pieces'

configuration of unicode separator string

    use charnames qw(:full);
    tie my %nbsp, 'Locale::Maketext::TieHash::nbsp', separator => "\N{NO-BREAK SPACE}";
    print $nbsp{'15 pieces'};
    # result is eq "15\N{NO-BREAK SPACE}pieces"

configuration of visible string

To test the script, store an visible string.

    tie my %nbsp, 'Locale::Maketext::TieHash::nbsp', separator => q{~};
    print $nbsp{'15 pieces'};
    # result: '15~pieces'

configuration using a subroutine

    tie my %nbsp, 'Locale::Maketext::TieHash::nbsp', sub => sub {
        (my $string = shift) =~ s{ }{*}msg;
        return $string;
    };
    print $nbsp{'15 pieces'};
    # result: '15*pieces'

write/read configuration

    my $former_code_ref = tied(%nbsp)->config(separator => $separator);

or

    my $former_code_ref = tied(%nbsp)->config(sub => $new_code_ref);

Back to Top


EXAMPLE

Inside of this Distribution is a directory named example. Run this *.pl files.

Back to Top


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.

Back to Top


SUBROUTINES/METHODS

method TIEHASH

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

'TIEHASH' ties your hash and set the options defaults.

method config

Stores the seperator string or a subroutine.

    tied(%nbsp)->config(
        sub => sub {
            (my $string = shift) =~ s{ }{ }msg;
            return $string;
        },
    );

or

    tied(%nbsp)->config(
        separator => ' ',
    );

'config' accepts all parameters as Hash and gives a Hash back with all set attributes.

method FETCH

Give your string as key of your hash. 'FETCH' will substitute the whitespace to ' ' and give it back as value.

    # Substitute
    print $nbsp{$string};

Back to Top


DIAGNOSTICS

All methods can croak at false parameters.

Back to Top


CONFIGURATION AND ENVIRONMENT

nothing

Back to Top


DEPENDENCIES

parent

the Tie::Sub manpage

the Params::Validate manpage Comfortable parameter validation

Back to Top


INCOMPATIBILITIES

not known

Back to Top


BUGS AND LIMITATIONS

not known

Back to Top


SEE ALSO

the Locale::Maketext manpage Localisation framework

the Tie::Hash manpage

Back to Top


AUTHOR

Steffen Winkler

Back to Top


LICENSE AND COPYRIGHT

Copyright (c) 2004 - 2009, Steffen Winkler <steffenw at cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Back to Top

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