| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 24 |  |  | 24 |  | 51934 | use strict; | 
|  | 24 |  |  |  |  | 43 |  | 
|  | 24 |  |  |  |  | 1051 |  | 
| 2 | 24 |  |  | 24 |  | 129 | use warnings; | 
|  | 24 |  |  |  |  | 34 |  | 
|  | 24 |  |  |  |  | 1286 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | package App::Embra::Role::Logging; | 
| 5 |  |  |  |  |  |  | $App::Embra::Role::Logging::VERSION = '0.001'; # TRIAL | 
| 6 |  |  |  |  |  |  | # ABSTRACT: adds logging methods to a class | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 24 |  |  | 24 |  | 13275 | use Log::Any; | 
|  | 24 |  |  |  |  | 37200 |  | 
|  | 24 |  |  |  |  | 97 |  | 
| 9 | 24 |  |  | 24 |  | 842 | use Method::Signatures; | 
|  | 24 |  |  |  |  | 40 |  | 
|  | 24 |  |  |  |  | 174 |  | 
| 10 | 24 |  |  | 24 |  | 8982 | use Moo::Role; | 
|  | 24 |  |  |  |  | 36 |  | 
|  | 24 |  |  |  |  | 198 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | has 'log_prefix' => ( | 
| 15 |  |  |  |  |  |  | is => 'lazy', | 
| 16 |  |  |  |  |  |  | ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 24 | 0 |  | 24 |  | 22188 | method _build_log_prefix { | 
|  | 0 |  |  | 0 |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 20 | 0 |  |  |  |  |  | return q{}; | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | has 'logger' => ( | 
| 25 |  |  |  |  |  |  | is => 'lazy', | 
| 26 |  |  |  |  |  |  | handles => [ Log::Any->logging_methods ], | 
| 27 |  |  |  |  |  |  | ); | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 24 | 0 |  | 24 |  | 12932 | method _build_logger { | 
|  | 0 |  |  | 0 |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | return Log::Any->get_logger; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | for my $logging_method ( Log::Any->logging_methods ) { | 
| 35 |  |  |  |  |  |  | around $logging_method => func( $orig, $self, $log_msg ) { | 
| 36 |  |  |  |  |  |  | $self->logger->$logging_method( $self->log_prefix . $log_msg ); | 
| 37 |  |  |  |  |  |  | }; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | 1; | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | __END__ | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =pod | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =encoding UTF-8 | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head1 NAME | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | App::Embra::Role::Logging - adds logging methods to a class | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 VERSION | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | version 0.001 | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | This role adds some basic logging methods to its implementer. It provides L<a C<logger> attribute|/logger>r which handles all of the standard log methods. | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head2 log_prefix | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | A string to prefix to all logged messages. Defaults to the empty string. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head2 logger | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | The object which handles all the logging. It must accept any of L<Log::Any's logging methods|Log::Any/logging_methods>. | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head1 METHODS | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head2 _build_log_prefix | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | say $app_embra_role_logging->_build_log_prefix; | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | Returns the log prefix. Present only so it can be modified by implementors with L<around|Method::Modifiers/around>. | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head2 _build_logger | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | my $logger = $app_embra_role_logging->_build_logger; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | Returns a new instance of L<Log::Any>. Present only so it can be modified by implementors with L<around|Method::Modifiers/around>. | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head1 AUTHOR | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | Daniel Holz <dgholz@gmail.com> | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | This software is copyright (c) 2015 by Daniel Holz. | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 93 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =cut |