1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# This code is part of Perl distribution Log-Report-Optional version 1.08.
# The POD got stripped from this file by OODoc version 3.04.
# For contributors see file ChangeLog.
# This software is copyright (c) 2013-2025 by Mark Overmeer.
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
#oodist: *** DO NOT USE THIS VERSION FOR PRODUCTION ***
#oodist: This file contains OODoc-style documentation which will get stripped
#oodist: during its release in the distribution. You can use this file for
#oodist: testing, however the code of this development version may be broken!
package Log::Report::Minimal::Domain;{
our $VERSION = '1.08';
}
use warnings;
use strict;
use String::Print 'oo';
#--------------------
sub new(@) { my $class = shift; (bless {}, $class)->init({@_}) }
sub init($)
{ my ($self, $args) = @_;
$self->{LRMD_name} = $args->{name} or Log::Report::panic();
$self;
}
#--------------------
sub name() { $_[0]->{LRMD_name} }
sub isConfigured() { $_[0]->{LRMD_where} }
sub configure(%)
{ my ($self, %args) = @_;
my $here = $args{where} || [caller];
if(my $s = $self->{LRMD_where})
{ my $domain = $self->name;
die "only one package can contain configuration; for $domain already in $s->[0] in file $s->[1] line $s->[2]. Now also found at $here->[1] line $here->[2]\n";
}
my $where = $self->{LRMD_where} = $here;
# documented in the super-class, the more useful man-page
my $format = $args{formatter} || 'PRINTI';
$format = {} if $format eq 'PRINTI';
if(ref $format eq 'HASH')
{ my $class = delete $format->{class} || 'String::Print';
my $method = delete $format->{method} || 'sprinti';
my $sp = $class->new(%$format);
$self->{LRMD_format} = sub { $sp->$method(@_) };
}
elsif(ref $format eq 'CODE')
{ $self->{LRMD_format} = $format;
}
else
{ error __x"illegal formatter `{name}' at {fn} line {line}", name => $format, fn => $where->[1], line => $where->[2];
}
$self;
}
#--------------------
sub interpolate(@)
{ my ($self, $msgid, $args) = @_;
$args->{_expand} or return $msgid;
my $f = $self->{LRMD_format} || $self->configure->{LRMD_format};
$f->($msgid, $args);
}
1;
|