This file is indexed.

/usr/share/perl5/Log/Dispatch/Configurator/Any.pm is in liblog-dispatch-configurator-any-perl 1.122640-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package Log::Dispatch::Configurator::Any;
{
  $Log::Dispatch::Configurator::Any::VERSION = '1.122640';
}

use strict;
use warnings FATAL => 'all';

use base 'Log::Dispatch::Configurator';
use Config::Any;
use Carp;

sub new {
    my($class, $file) = @_;
    my $self = {};

    # allow passing of hashref or filename
    if (ref $file) {
        croak "Config must be hashref or filename"
            if ref $file ne 'HASH';

        $self = bless { file => undef, _config => $file }, $class;
    }
    else {
        $self = bless { file => $file }, $class;
        $self->parse_file;
    }

    return bless $self, $class;
}

sub parse_file {
    my $self = shift;
    my $file = $self->{'file'};

    my $config = eval{ Config::Any->load_files({
        files => [$file],
        use_ext => 1,
        flatten_to_hash => 1,
    })->{$file} };

    croak "Config '$file' does not build a Hash"
        if $@ or (ref $config ne 'HASH');
    $self->{'_config'} = $config;
}

sub reload {
    my $self = shift;
    return if !defined $self->{file};
    $self->parse_file;
}

sub get_attrs_global {
    my $self = shift;
    my $attrs;

    foreach (keys %{$self->{_config}}) {
        next if ref $self->{'_config'}->{$_} eq 'HASH';
        $attrs->{$_} = $self->{'_config'}->{$_};
    }

    # fix for Config::General squashing single item list to a scalar
    $attrs->{dispatchers} = [$attrs->{dispatchers}]
        if ! ref $attrs->{dispatchers};

    return $attrs;
}

sub get_attrs {
      my($self, $name) = @_;
      return $self->{'_config'}->{$name};
}

1;


# ABSTRACT: Configurator implementation with Config::Any


__END__
=pod

=head1 NAME

Log::Dispatch::Configurator::Any - Configurator implementation with Config::Any

=head1 VERSION

version 1.122640

=head1 PURPOSE

Use this module in combination with L<Log::Dispatch::Config> to allow many
formats of configuration file to be loaded, via the L<Config::Any> module.

=head1 SYNOPSIS

In the traditional Log::Dispatch::Config way:

 use Log::Dispatch::Config; # loads Log::Dispatch
 use Log::Dispatch::Configurator::Any;
  
 my $config = Log::Dispatch::Configurator::Any->new('log.yml');
 Log::Dispatch::Config->configure($config);
  
 # nearby piece of code
 my $log = Log::Dispatch::Config->instance;
 $log->alert('Hello, world!');

Alternatively, without a config file on disk:

 use Log::Dispatch::Config; # loads Log::Dispatch
 use Log::Dispatch::Configurator::Any;
  
 my $confhash = {
     dispatchers => ['screen]',
     screen = {
         class => 'Log::Dispatch::Screen',
         min_level => 'debug',
     },
 };
  
 my $config = Log::Dispatch::Configurator::Any->new($confhash);
 Log::Dispatch::Config->configure($config);
  
 # nearby piece of code
 my $log = Log::Dispatch::Config->instance;
 $log->alert('Hello, world!');

=head1 DESCRIPTION

L<Log::Dispatch::Config> is a wrapper for L<Log::Dispatch> and provides a way
to configure Log::Dispatch objects with configuration files. Somewhat like a
lite version of log4j and L<Log::Log4perl> it allows multiple log
destinations. The standard configuration file format for Log::Dispatch::Config
is AppConfig.

This module plugs in to Log::Dispatch::Config and allows the use of other file
formats, in fact any format supported by the L<Config::Any> module. As a bonus
you can also pass in a configuration data structure instead of a file name.

=head1 USAGE

Follow the examples in the L</SYNOPSIS>. If you are using an external
configuration file, be aware that you are required to use a filename extension
(e.g.  C<.yml> for YAML).

Below are a couple of tips and tricks you may find useful.

=head2 Fall-back default config

Being able to use a configuration data structre instead of a file on disk is
handy when you want to provide application defaults which the user then
replaces with their own settings. For example you could have the following:

 my $defaults = {
     dispatchers => ['screen'],
     screen => {
         class     => 'Log::Dispatch::Screen',
         min_level => 'debug',
     },
 };
  
 my $config_file = '/etc/myapp_logging.conf';
 my $config = $ENV{MYAPP_LOGGING_CONFIG} || $ARGV[0] ||
     ( -e $config_file ? $config_file : $defaults);
 
 Log::Dispatch::Config->configure_and_watch(
     Log::Dispatch::Configurator::Any->new($config) );
 my $dispatcher = Log::Dispatch::Config->instance;

With the above code, your application will check for a filename in an
environment variable, then a filename as a command line argument, then check
for a file on disk, and finally use its built-in defaults.

=head2 Dealing with a C<dispatchers> list

L<Log::Dispatch::Config> requires that a global setting C<dispatchers> have a
list value (i.e. your list of dispatchers). A few config file formats do not
support list values at all, or list values at the global level (two examples
being L<Config::Tiny> and L<Config::General>).

This module allows you to have a small grace when there is only one dispatcher
in use. Write the configuration file normally, and the single-item
C<dispatchers> value will automatically be promoted to a list. In other words:

 # myapp.ini
 dispatchers = screen
 
 # this becomes a config of:
 $config = { dispatchers => 'screen', ... };
 
 # so this module promotes it to:
 $config = { dispatchers => ['screen'], ... };

If you want more than one dispatcher, you then need to use a config file
format which supports these lists natively, I'm afraid. A good suggestion
might be YAML.

=head1 THANKS

My thanks to C<miyagawa> for writing Log::Dispatch::Config, from where I also took
some tests. Also thanks to Florian Merges for his YAML Configurator, which was
a useful example and saved me much time.

=head1 AUTHOR

Oliver Gorwits <oliver@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by University of Oxford.

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

=cut