File Coverage

lib/Log/Shiras/LogSpace.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 4 75.0
condition 3 6 50.0
subroutine 9 9 100.0
pod 1 1 100.0
total 46 50 92.0


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