NAME
Locale::Utils::PlaceholderNamed - Utils to expand named placeholders
$Id: PlaceholderNamed.pm 587 2015-04-16 05:58:10Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/Locale-Utils-PlaceholderNamed/trunk/lib/Locale/Utils/PlaceholderNamed.pm $
VERSION
1.002
SYNOPSIS
use Locale::Utils::PlaceholderNamed;
my $obj = Locale::Utils::PlaceholderNamed->new(
# optional is_strict switch
is_strict => 1,
# optional modifier code
modifier_code => sub {
my ( $value, $attribute ) = @_;
return
$attribute eq '%.3f'
? sprintf($attribute, $value)
: $attribute eq 'accusative'
? accusative($value)
: $value;
},
);
$expanded = $obj->expand_named($text, %args);
$expanded = $obj->expand_named($text, \%args);
DESCRIPTION
Utils to expand named placeholders.
SUBROUTINES/METHODS
method new
see SYNOPSIS
method is_strict
If is_strict is false: undef will be converted to q{}. If is_strict is true: no replacement.
$obj->is_strict(1); # boolean true or false;
method modifier_code, clear_modifier_code
The modifier code handles named attributes to modify the given placeholder value.
If the placeholder name is {foo:bar}
then foo is the placeholder name and bar the attribute name. Space in front of the attribute name is allowed, e.g. {foo :bar}
.
my $code_ref = sub {
my ( $value, $attribute ) = @_;
return
$attribute eq 'num.03'
? sprintf('%.03f, $value)
: $attribute eq 'accusative'
? accusative($value)
: $value;
};
$obj->modifier_code($code_ref);
To switch off this code - clear them.
$obj->clear_modifier_code;
method expand_named
Expands strings containing named placeholders like {name}
.
$text = 'foo {name} baz';
%args = (
name => 'bar',
);
$expanded = $obj->expand_named($text, %args);
or
$expanded = $obj->expand_text($text, \%args);
JAVASCRIPT
Inside of this distribution is a directory named javascript. For more information see: Locale::TextDomain::OO::JavaScript
This script depends on http://jquery.com/.
EXAMPLE
Inside of this distribution is a directory named example. Run the *.pl files.
DIAGNOSTICS
none
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
INCOMPATIBILITIES
not known
BUGS AND LIMITATIONS
not known
SEE ALSO
http://en.wikipedia.org/wiki/Gettext
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2011 - 2017, 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.