File Coverage

lib/Log/Shiras/LogSpace.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition 3 6 50.0
subroutine 7 7 100.0
pod 1 1 100.0
total 38 42 90.4


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