Log::Report::Domain(3pm) | User Contributed Perl Documentation | Log::Report::Domain(3pm) |
Log::Report::Domain - administer one text-domain
Log::Report::Domain is a Log::Report::Minimal::Domain Log::Report::Domain is extended by Log::Report::Template::Textdomain
# internal usage use Log::Report::Domain; my $domain = Log::Report::Domain->new(name => $name); # find a ::Domain object use Log::Report 'my-domain'; my $domain = textdomain 'my-domain'; # find domain config my $domain = textdomain; # config of this package # explicit domain configuration package My::Package; use Log::Report 'my-domain'; # set textdomain for package textdomain $name, %configure; # set config, once per program (textdomain $name)->configure(%configure); # same textdomain->configure(%configure); # same if current package in $name # implicit domain configuration package My::Package; use Log::Report 'my-domain', %configure; # external file for configuration (perl or json format) use Log::Report 'my-domain', config => $filename; use Log::Report 'my-domain'; textdomain->configure(config => $filename);
Log::Report can handle multiple sets of packages at the same time: in the usual case a program consists of more than one software distribution, each containing a number of packages. Each module in an application belongs to one of these sets, by default the domain set 'default'.
For "Log::Report", those packags sets are differentiated via the text-domain value in the "use" statement:
use Log::Report 'my-domain';
There are many things you can configure per (text)domain. This is not only related to translations, but also -for instance- for text formatting configuration. The administration for the configuration is managed in this package.
Extends "DESCRIPTION" in Log::Report::Minimal::Domain.
Extends "METHODS" in Log::Report::Minimal::Domain.
Extends "Constructors" in Log::Report::Minimal::Domain.
-Option--Defined in --Default name Log::Report::Minimal::Domain <required>
Extends "Attributes" in Log::Report::Minimal::Domain.
-Option --Defined in --Default config undef context_rules undef formatter PRINTI native_language 'en_US' translator created internally where Log::Report::Minimal::Domain <required>
Currently, this file can be in Perl native format (when ending on ".pl") or JSON (when it ends with ".json"). Various modules may explain parts of what can be found in these files, for instance Log::Report::Translator::Context.
Contexts are totally ignored then there are no "context_rules". When you do not wish to change settings, you may simply provide a HASH.
example:
use Log::Report 'my-domain', context_rules => {};
Extends "Action" in Log::Report::Minimal::Domain.
Configuration of a domain can happen in many ways: either explicitly or implicitly. The explicit form:
package My::Package; use Log::Report 'my-domain'; textdomain 'my-domain', %configuration; textdomain->configure(%configuration); textdomain->configure(\%configuration); textdomain->configure(conf => $filename);
The implicit form is (no variables possible, only constants!)
package My::Package; use Log::Report 'my-domain', %configuration; use Log::Report 'my-domain', conf => '/filename';
You can only configure your domain in one place in your program. The textdomain setup is then used for all packages in the same domain.
This also works for Log::Report::Optional, which is a dressed-down version of Log::Report.
configuring your own formatter
[0.91] The "PRINTI" is a special constants for configure(formatter), and will use String::Print function "printi()", with the standard tricks.
textdomain 'some-domain' formatter => { class => 'String::Print' # default , method => 'sprinti' # default , %options # constructor options for the class );
When you want your own formatter, or configuration of "String::Print", you need to pass a CODE. Be aware that you may loose magic added by Log::Report and other layers, like Log::Report::Template:
textdomain 'some-domain' , formatter => \&my_formatter;
configuring global values
Say, you log for a (Dancer) webserver, where you wish to include the website name in some of the log lines. For this, (ab)use the translation context:
### first enabled translation contexts use Log::Report 'my-domain', context_rules => {}; # or use Log::Report 'my-domain'; textdomain->configure(context_rules => {}); # or textdomain 'my-domain' , content_rules => {}; ### every time you start working for a different virtual host (textdomain 'my-domain')->setContext(host => $host); ### now you can use that in your code package My::Package; use Log::Report 'my-domain'; error __x"in {_context.host} not logged-in {user}", user => $username;
This module is part of Log-Report distribution version 1.36, built on October 27, 2023. Website: http://perl.overmeer.net/CPAN/
Copyrights 2007-2023 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/
2023-10-29 | perl v5.36.0 |