File Coverage

blib/lib/Log/Report/Minimal/Domain.pm
Criterion Covered Total %
statement 31 37 83.7
branch 5 12 41.6
condition 6 11 54.5
subroutine 8 10 80.0
pod 5 6 83.3
total 55 76 72.3


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