/usr/share/perl5/Log/Any/Adapter/Util.pm is in liblog-any-perl 1.038-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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | use 5.008001;
use strict;
use warnings;
package Log::Any::Adapter::Util;
# ABSTRACT: Common utility functions for Log::Any
our $VERSION = '1.038';
use Exporter;
our @ISA = qw/Exporter/;
my %LOG_LEVELS;
BEGIN {
%LOG_LEVELS = (
EMERGENCY => 0,
ALERT => 1,
CRITICAL => 2,
ERROR => 3,
WARNING => 4,
NOTICE => 5,
INFO => 6,
DEBUG => 7,
TRACE => 8,
);
}
use constant \%LOG_LEVELS;
our @EXPORT_OK = qw(
cmp_deeply
detection_aliases
detection_methods
dump_one_line
log_level_aliases
logging_aliases
logging_and_detection_methods
logging_methods
make_method
numeric_level
read_file
require_dynamic
);
push @EXPORT_OK, keys %LOG_LEVELS;
our %EXPORT_TAGS = ( 'levels' => [ keys %LOG_LEVELS ] );
my ( %LOG_LEVEL_ALIASES, @logging_methods, @logging_aliases, @detection_methods,
@detection_aliases, @logging_and_detection_methods );
BEGIN {
%LOG_LEVEL_ALIASES = (
inform => 'info',
warn => 'warning',
err => 'error',
crit => 'critical',
fatal => 'critical'
);
@logging_methods =
qw(trace debug info notice warning error critical alert emergency);
@logging_aliases = keys(%LOG_LEVEL_ALIASES);
@detection_methods = map { "is_$_" } @logging_methods;
@detection_aliases = map { "is_$_" } @logging_aliases;
@logging_and_detection_methods = ( @logging_methods, @detection_methods );
}
#pod =func logging_methods
#pod
#pod Returns a list of all logging method. E.g. "trace", "info", etc.
#pod
#pod =cut
sub logging_methods { @logging_methods }
#pod =func detection_methods
#pod
#pod Returns a list of detection methods. E.g. "is_trace", "is_info", etc.
#pod
#pod =cut
sub detection_methods { @detection_methods }
#pod =func logging_and_detection_methods
#pod
#pod Returns a list of logging and detection methods (but not aliases).
#pod
#pod =cut
sub logging_and_detection_methods { @logging_and_detection_methods }
#pod =func log_level_aliases
#pod
#pod Returns key/value pairs mapping aliases to "official" names. E.g. "err" maps
#pod to "error".
#pod
#pod =cut
sub log_level_aliases { %LOG_LEVEL_ALIASES }
#pod =func logging_aliases
#pod
#pod Returns a list of logging alias names. These are the keys from
#pod L</log_level_aliases>.
#pod
#pod =cut
sub logging_aliases { @logging_aliases }
#pod =func detection_aliases
#pod
#pod Returns a list of detection aliases. E.g. "is_err", "is_fatal", etc.
#pod
#pod =cut
sub detection_aliases { @detection_aliases }
#pod =func numeric_level
#pod
#pod Given a level name (or alias), returns the numeric value described above under
#pod log level constants. E.g. "err" would return 3.
#pod
#pod =cut
sub numeric_level {
my ($level) = @_;
my $canonical =
exists $LOG_LEVEL_ALIASES{$level} ? $LOG_LEVEL_ALIASES{$level} : $level;
return $LOG_LEVELS{ uc($canonical) };
}
#pod =func dump_one_line
#pod
#pod Given a reference, returns a one-line L<Data::Dumper> dump with keys sorted.
#pod
#pod =cut
# lazy trampoline to load Data::Dumper only on demand but then not try to
# require it pointlessly each time
*dump_one_line = sub {
require Data::Dumper;
my $dumper = sub {
my ($value) = @_;
return Data::Dumper->new( [$value] )->Indent(0)->Sortkeys(1)->Quotekeys(0)
->Terse(1)->Useqq(1)->Dump();
};
my $string = $dumper->(@_);
no warnings 'redefine';
*dump_one_line = $dumper;
return $string;
};
#pod =func make_method
#pod
#pod Given a method name, a code reference and a package name, installs the code
#pod reference as a method in the package.
#pod
#pod =cut
sub make_method {
my ( $method, $code, $pkg ) = @_;
$pkg ||= caller();
no strict 'refs';
*{ $pkg . "::$method" } = $code;
}
#pod =func require_dynamic (DEPRECATED)
#pod
#pod Given a class name, attempts to load it via require unless the class
#pod already has a constructor available. Throws an error on failure. Used
#pod internally and may become private in the future.
#pod
#pod =cut
sub require_dynamic {
my ($class) = @_;
return 1 if $class->can('new'); # duck-type that class is loaded
unless ( defined( eval "require $class; 1" ) )
{ ## no critic (ProhibitStringyEval)
die $@;
}
}
#pod =func read_file (DEPRECATED)
#pod
#pod Slurp a file. Does *not* apply any layers. Used for testing and may
#pod become private in the future.
#pod
#pod =cut
sub read_file {
my ($file) = @_;
local $/ = undef;
open( my $fh, '<:utf8', $file ) ## no critic
or die "cannot open '$file': $!";
my $contents = <$fh>;
return $contents;
}
#pod =func cmp_deeply (DEPRECATED)
#pod
#pod Compares L<dump_one_line> results for two references. Also takes a test
#pod label as a third argument. Used for testing and may become private in the
#pod future.
#pod
#pod =cut
sub cmp_deeply {
my ( $ref1, $ref2, $name ) = @_;
my $tb = Test::Builder->new();
$tb->is_eq( dump_one_line($ref1), dump_one_line($ref2), $name );
}
# 0.XX version loaded Log::Any and some adapters relied on this happening
# behind the scenes. Since Log::Any now uses this module, we load Log::Any
# via require after compilation to mitigate circularity.
require Log::Any;
1;
# vim: ts=4 sts=4 sw=4 et tw=75:
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Any::Adapter::Util - Common utility functions for Log::Any
=head1 VERSION
version 1.038
=head1 DESCRIPTION
This module has utility functions to help develop L<Log::Any::Adapter>
subclasses or L<Log::Any::Proxy> formatters/filters. It also has some
functions used in internal testing.
=head1 USAGE
Nothing is exported by default.
=head2 Log level constants
If the C<:levels> tag is included in the import list, the following numeric
constants will be imported:
EMERGENCY => 0
ALERT => 1
CRITICAL => 2
ERROR => 3
WARNING => 4
NOTICE => 5
INFO => 6
DEBUG => 7
TRACE => 8
=head1 NAME
Log::Any::Adapter::Util - Common utility functions for Log::Any
=head1 VERSION
version 1.038
=head1 FUNCTIONS
=head2 logging_methods
Returns a list of all logging method. E.g. "trace", "info", etc.
=head2 detection_methods
Returns a list of detection methods. E.g. "is_trace", "is_info", etc.
=head2 logging_and_detection_methods
Returns a list of logging and detection methods (but not aliases).
=head2 log_level_aliases
Returns key/value pairs mapping aliases to "official" names. E.g. "err" maps
to "error".
=head2 logging_aliases
Returns a list of logging alias names. These are the keys from
L</log_level_aliases>.
=head2 detection_aliases
Returns a list of detection aliases. E.g. "is_err", "is_fatal", etc.
=head2 numeric_level
Given a level name (or alias), returns the numeric value described above under
log level constants. E.g. "err" would return 3.
=head2 dump_one_line
Given a reference, returns a one-line L<Data::Dumper> dump with keys sorted.
=head2 make_method
Given a method name, a code reference and a package name, installs the code
reference as a method in the package.
=head2 require_dynamic (DEPRECATED)
Given a class name, attempts to load it via require unless the class
already has a constructor available. Throws an error on failure. Used
internally and may become private in the future.
=head2 read_file (DEPRECATED)
Slurp a file. Does *not* apply any layers. Used for testing and may
become private in the future.
=head2 cmp_deeply (DEPRECATED)
Compares L<dump_one_line> results for two references. Also takes a test
label as a third argument. Used for testing and may become private in the
future.
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz <swartz@pobox.com>
=item *
David Golden <dagolden@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Jonathan Swartz and David Golden.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz <swartz@pobox.com>
=item *
David Golden <dagolden@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Jonathan Swartz and David Golden.
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
|