File Coverage

lib/Log/Shiras/LogSpace.pm
Criterion Covered Total %
statement 33 33 100.0
branch 3 4 75.0
condition 3 6 50.0
subroutine 10 10 100.0
pod 1 1 100.0
total 50 54 92.5


line stmt bran cond sub pod time code
1             package Log::Shiras::LogSpace;
2             our $AUTHORITY = 'cpan:JANDREW';
3 2     2   821136 use version; our $VERSION = version->declare("v0.48.0");
  2         4  
  2         16  
4 2     2   174 use strict;
  2         3  
  2         45  
5 2     2   8 use warnings;
  2         3  
  2         51  
6 2     2   46 use 5.010;
  2         6  
7 2     2   10 use utf8;
  2         3  
  2         14  
8 2     2   48 use lib '../../';
  2         3  
  2         13  
9 2     2   219 use Moose::Role;
  2         3  
  2         17  
10 2     2   9091 use MooseX::Types::Moose qw( Str );
  2         3  
  2         20  
11              
12             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
13              
14             has log_space =>(
15             isa => Str,
16             reader => 'get_log_space',
17             writer => 'set_log_space',
18             predicate => 'has_log_space',
19             default => sub{
20             my( $self ) = @_;
21             my $ref = ref $self ? ref( $self ) : $self;
22             if( $self->can( 'get_class_space' ) ){# avoid duplicating class space at the end
23             my $class_space = $self->get_class_space;
24             if( $ref =~ /(.*)(::$class_space)/ ){
25             $ref = $1;
26             }
27             }
28             return $ref;
29             }
30             );
31              
32             #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
33              
34             sub get_all_space{
35 2     2 1 4 my ( $self, $add_string ) = @_;
36 2         52 my $all_space = $self->get_log_space;
37 2 50 33     14 if( $self->can( 'get_class_space' ) and length( $self->get_class_space ) > 0 ){
38 2         14 $all_space .= '::' . $self->get_class_space;
39             }
40 2 100 66     14 if( $add_string and length( $add_string ) > 0 ){
41 1         2 $all_space .= '::' . $add_string;
42             }
43 2         6 return $all_space;
44             }
45              
46             #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
47              
48             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
49              
50             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
51              
52 2     2   9116 no Moose::Role;
  2         5  
  2         13  
53              
54             1;
55             # The preceding line will help the module return a true value
56              
57             #########1 main POD docs 3#########4#########5#########6#########7#########8#########9
58              
59             __END__
60              
61             =head1 NAME
62              
63             Log::Shiras::LogSpace - Log::Shiras Role for runtime name-spaces
64              
65             =head1 SYNOPSIS
66              
67             use Modern::Perl;
68             use MooseX::ShortCut::BuildInstance qw( build_class );
69             use Log::Shiras::LogSpace;
70             my $test_instance = build_class(
71             package => 'Generic',
72             roles =>[ 'Log::Shiras::LogSpace' ],
73             add_methods =>{
74             get_class_space => sub{ 'ExchangeStudent' },
75             i_am => sub{
76             my( $self )= @_;
77             print "I identify as a: " . $self->get_all_space( 'individual' ) . "\n";
78             }
79             },
80             );
81             my $Generic = $test_instance->new;
82             my $French = $test_instance->new( log_space => 'French' );
83             my $Spanish = $test_instance->new( log_space => 'Spanish' );
84             $Generic->i_am;
85             $French->i_am;
86             $Spanish->i_am;
87              
88             #######################################################################################
89             # Synopsis Screen Output
90             # 01: I identify as a: Generic::ExchangeStudent::individual
91             # 02: I identify as a: French::ExchangeStudent::individual
92             # 03: I identify as a: Spanish::ExchangeStudent::individual
93             #######################################################################################
94              
95             =head1 DESCRIPTION
96              
97             This attribute is useful to manage runtime L<Log::Shiras> caller namespace. In the case
98             where MyCoolPackage with Log::Shiras lines is used in more than one context then it is
99             possible to pass a context sensitive name to the attribute log_space on intantiation of the
100             instance and have the namespace bounds only activate the desired context of the package
101             rather than have it report everywhere it is used. The telephone call in this case would
102             look something like this;
103              
104             package MyCoolPackage
105              
106             sub get_class_space{ 'MyCoolPackage' }
107              
108             sub my_cool_sub{
109             my( $self, $message ) = @_;
110             my $phone = Log::Shiras::Telephone->new(
111             name_space => $self->get_all_space . '::my_cool_sub',
112             );
113             $phone->talk( level => 'debug',
114             message => "Arrived at my_cool_sub with the message: $message" );
115             # Do something cool here!
116             }
117              
118             In this case if you used my cool package instances with the log_space set to different
119             values then only the namespace unblocked for 'FirstInstance::MyCoolPackage::my_cool_sub'
120             would report. See the documentation for L<get_all_space|/get_all_space> for details.
121              
122             As a general rule it works best if the subroutine 'get_class_space' is defined in an object
123             class file (not a role file). Each subroutine space can be identified with the $add_string
124             passed to get_all_space.
125              
126             =head2 Attributes
127              
128             Data passed to new when creating an instance of the consuming class. For modification of
129             this attribute see the listed L<attribute methods|/attribute methods>.
130              
131             =head3 log_space
132              
133             =over
134              
135             B<Definition:> This will be the base log_space element returned by L<get_all_space
136             |/get_all_space>
137              
138             B<Default> the consuming package name
139              
140             B<Range> Any string, but Log::Shiras will look for '::' separators
141              
142             B<attribute methods>
143              
144             =over
145              
146             B<get_log_space>
147              
148             =over
149              
150             B<Definition:> Returns the attribute value
151              
152             =back
153              
154             B<set_log_space( $string )>
155              
156             =over
157              
158             B<Definition:> sets the attribute value
159              
160             =back
161              
162             B<has_log_space>
163              
164             =over
165              
166             B<Definition:> predicate test for the attribute
167              
168             =back
169              
170             =back
171              
172             =back
173              
174             =head2 Method
175              
176             =head3 get_all_space( $add_string )
177              
178             =over
179              
180             B<Definition:> This method collects the stored 'log_space' attribute value and then
181             joins it with the results of a method call to 'get_class_space'. The 'get_class_space'
182             attribute should be provided somewhere else in the class. The two values are joined with
183             '::'. It will additionally join another string argument passed as $add_string to form a
184             complete log space stack. See synopsis.
185              
186             B<Accepts> $add_string
187              
188             B<Returns> log_space . '::' . $self->get_class_space . '::' . $add_string as each element
189             is available.
190              
191             =back
192              
193             =head1 SUPPORT
194              
195             =over
196              
197             L<github Spreadsheet::XLSX::Reader::LibXML/issues
198             |https://github.com/jandrew/Spreadsheet-XLSX-Reader-LibXML/issues>
199              
200             =back
201              
202             =head1 TODO
203              
204             =over
205              
206             B<1.> Nothing Yet
207              
208             =back
209              
210             =head1 AUTHOR
211              
212             =over
213              
214             =item Jed Lund
215              
216             =item jandrew@cpan.org
217              
218             =back
219              
220             =head1 COPYRIGHT
221              
222             This program is free software; you can redistribute
223             it and/or modify it under the same terms as Perl itself.
224              
225             The full text of the license can be found in the
226             LICENSE file included with this module.
227              
228             =head1 DEPENDENCIES
229              
230             =over
231              
232             L<Moose::Role>
233              
234             L<MooseX::Types::Moose>
235              
236             =back
237              
238             =cut
239              
240             #########1#########2 main pod documentation end 5#########6#########7#########8#########9