blib/lib/Acme/Machi.pm

filter: Statementstmt 100% 73 / 73 Branchbran 78.1% 25 / 32 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 20 / 20 Podpod 100% 8 / 8 totaltotal 91.1% 133 / 146 CC 21 SCAR 17.1
CC
21
Cov
91%
search_file_from
13.1
affectionate
3.5
have_the_habit_of
3.0
CRAP 5.5
↑ Summary
1 2 package Acme::Machi v1.00.1 {
2
3 2 ▶ use v5.16.2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶ use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #import CPAN libs
14 2 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16
17 =head1 NAME
18
19 Machi - Awesome Machi here!
20  
21 =head1 VERSION
22  
23 Version v1.00.1
24  
25 =cut
26  
27 =head1 SYNOPSIS
28  
29 Quick summary of what the module does.
30 Exactly a little code snippet.
31  
32 use Acme::Machi;
33  
34 my $loli = Acme::Machi->new( $name ); # Give birth to a person; accept an optional argument to set the person's name.
35  
36 $loli->named( $name ); # Name the person. Default name is 'Machi'.
37  
38 $loli->name(); # Get person's name.
39  
40 $loli->have_the_habit_of( $habit ); # Person gets into certain searching habit.
41  
42 $loli->habit(); # Get one's searching habit.
43  
44 $loli->learning( @words ); # Teach the person saying something endearing.
45  
46 $loli->affectionate( $file_handle ); # The person shall randomly tell about what you previously teached her/him to say.
47  
48 $loli->search_file_from( $target, $dir, $RESP ); # Search file/dir from certain spcified directory using BFS or DFS.
49 # The third argument $RESP representing 'Responsible', which means she/he will
50 # stop searching and come back in a moment when finding the target one.
51 # In case $RESP is in zero state or $RESP is set but the target isn't found,
52 # she/he will finally print out the tree-like structure of your file system
53 # before coming back in despair.
54
55
56 =head1 METHODS
57  
58 =head2 new
59  
60 Create a Machi-type instance.
61  
62 =cut
63 6 ▶ sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
64 6 ▶ (ref $_[0]) && croak "Oops! Cannot use instance method to construt an object!";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] and croak("Oops! Cannot use instance method to construt an object!") 1 5 6
65 5 ▶ bless {
Condition100%2/2
$_[1] // "Machi"
l!l
14
MC/DC100%1/1
$_[1] // "Machi"
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
66 Name => $_[1] // "Machi",
67 Words => ["I am starving!!"], # In general, creatures always know how to express their hunger.
68 SRCH_Habit => 'BFS',
69 }, $_[0];
70 }
71  
72 =head2 named
73  
74 Assign a new value to scalar-type instance variable, 'Name', in the object.
75 Return: value of assignment.
76  
77 =cut
78 1 ▶ sub named {
Subroutine named: called CC=2 SCAR=7.2
Pod documented
79 1 ▶ (ref $_[0]) || croak "Oops! Cannot use class method setting the object!";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or croak("Oops! Cannot use class method setting the object!") 1 0 1
80 1 $_[0]{Name} = $_[1];
81 }
82  
83 =head2 name
84  
85 Return: person's name.
86  
87 =cut
88 45 ▶ sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
89 45 $_[0]{Name};
90 }
91  
92  
93 =head2 have_the_habit_of
94  
95 Assign a new searching habit to scalar-type instance variable, 'SRCH_Habit'.
96 Only strings 'BFS' and 'DFS' are valid, setting the others will be ignored.
97 Return: value of assignment.
98  
99 =cut
100 5 ▶ sub have_the_habit_of {
Subroutine have_the_habit_of: called CC=3 SCAR=11.1
Pod documented
101 5 ▶ (ref $_[0]) || croak "Oops! Cannot use class method setting the object!";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or croak("Oops! Cannot use class method setting the object!") 5 0 5
102 5 ▶ $_[0]{SRCH_Habit} = $_[1] if($_[1] =~ m/([DB]FS)/);
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] =~ /([DB]FS)/u 4 1 5
103 }
104  
105 =head2 habit
106  
107 Return: person's searching habit.
108  
109 =cut
110 6 ▶ sub habit {
Subroutine habit: called CC=1 SCAR=0.0
Pod documented
111 6 $_[0]{SRCH_Habit};
112 }
113  
114  
115 =head2 learning
116  
117 Append a list of words to array-type instance variable, 'Words', in the object.
118 Return: how many words have she/he learnt.
119  
120 =cut
121 1 ▶ sub learning {
Subroutine learning: called CC=2 SCAR=7.1
Pod documented
122 1 ▶ (ref $_[0]) || croak "Oops! Cannot use class method setting the object!";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or croak("Oops! Cannot use class method setting the object!") 1 0 1
123 1 unshift (@{$_[0]{Words}}, @_[1 .. $#_]);
124 }
125
126 =head2 affectionate
127  
128 Randomly output one of predefined words to FILE_HANDLE, which default of is STDOUT.
129 Return: 1 if no problems while calling this method.
130  
131 =cut
132 42 ▶ sub affectionate {
Subroutine affectionate: called CC=3 SCAR=12.5
Pod documented
133 42 ▶ (ref $_[0]) || croak "Oops! Cannot call affectionate() using class method!";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or croak("Oops! Cannot call affectionate() using class method!") 42 0 42
134 42 my $words_list = $_[0]{Words};
135 42 ▶ ($_[1] // *STDOUT)->print( $_[0]->name(),": ", $words_list->[int(rand($#$words_list))], "\n");
Condition33%1/3
$_[1] // *STDOUT
l!l&&r!l&&!r
4200
MC/DC0%0/2
$_[1] // *STDOUT
$_[1] *STDOUT
Truth table33%1/3
A // B
A= $_[1]B= *STDOUT
ABresult
1X1
011
000
136 }
137
138
139 =head2 search_file_from
140  
141 Using BFS or DFS to search the target from certain directory.
142 Return: a two-element list:
143 the first element is boolean value denoting whether the target was found or not.
144 the second element is the result string outputed from the core module, Data::Dumper.
145 You may get to know files distribution even better after printing the string.
146  
147 =cut
148 4 ▶ sub search_file_from {
Subroutine search_file_from: called CC=13 SCAR=25.7
Pod documented
149 4 ▶ ref $_[0] || croak "Oops! Cannot ask non-human to search!";
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] or croak("Oops! Cannot ask non-human to search!") 4 0 4
150 4 my ($target, $dir, $RESP) = @_[1,2,3];
151 4 my $obj = File::Spec->catfile(getcwd, $target);
152 4 my $s_dir = File::Spec->catfile(getcwd, $dir);
153 my $push_front_back = ($_[0]->habit() eq 'DFS')?
154 57 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
155 57 unshift(@{$_[0]}, $_[1]);
156 }
157 57 ▶ : sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
158 57 push(@{$_[0]}, $_[1]);
159 4 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->habit eq 'DFS' ? : 2 2 4
160  
161 4 my $data = {};
162 4 my @queue = ( [$s_dir, $data] );
163 4 my ($elm, $np, $nd, $key, $found);
164 4 ▶ ($obj eq $s_dir) && ($found = 1);
Branch: 1 branch
BranchTrueFalseTotal
$obj eq $s_dir and $found = 1 0 4 4
165 4 ▶ return 1 if $RESP;
Branch: 1 branch
BranchTrueFalseTotal
if $RESP 2 2 4
166 2 ▶ while($elm = shift @queue){;
Branch: 1 branch
BranchTrueFalseTotal
if ($elm = shift @queue) 116 2 118
167 116 ($np, $nd) = @$elm;
168 116 $key = basename($np);
169 116 ▶ $nd->{$key} = (-l $np or -f _)? undef : +{};
Branch: 1 branch
BranchTrueFalseTotal
-l $np || -f _ ? : 82 34 116
Condition66%2/3
-l $np or -f _
l!l&&r!l&&!r
08234
MC/DC50%1/2
-l $np or -f _
-l $np -f _
Truth table66%2/3
A or B
A= -l $npB= -f _
ABresult
1X1
011
000
170 116 ▶ if (ref $nd->{$key}) {;
Branch: 1 branch
BranchTrueFalseTotal
if (ref $nd->{$key}) 34 82 116
171 34 my $dh = IO::Dir->new("$np");
172 34 my $npp;
173 34 foreach ($dh->read()) {;
174 182 $npp = File::Spec->catfile($np,$_);
175 182 ▶ ($obj eq $npp) && ($found = 1);
Branch: 1 branch
BranchTrueFalseTotal
$obj eq $npp and $found = 1 2 180 182
176 182 ▶ return 1 if $RESP;
Branch: 1 branch
BranchTrueFalseTotal
if $RESP 0 182 182
177 182 ▶ (m/\A\.{1,2}?\z/aa) || $push_front_back->(\@queue, [ $npp, $nd->{$key} ]);
Branch: 1 branch
BranchTrueFalseTotal
/\A\.{1,2}?\z/aa or &$push_front_back(\@queue, [$npp, $nd->{$key}]) 68 114 182
178 }
179 }
180 }
181 2 print Data::Dumper->Dump([\$data],[qw% *data %]);
182 2 $found;
183 }
184
185  
186 =head1 AUTHOR
187  
188 Machi Amayadori, C<< <Eosin at Syaro.Cafe> >>
189  
190 =head1 BUGS
191  
192 Please report any bugs or feature requests to C<bug-acme-machi at rt.cpan.org>, or through the web interface at
193 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-Machi>.
194 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
195  
196  
197  
198 =head1 SUPPORT
199  
200 You can find documentation for this module with the perldoc command.
201  
202 perldoc Acme::Machi
203  
204  
205 You can also look for information at:
206  
207 =over 4
208  
209 =item * RT: CPAN's request tracker (report bugs here)
210  
211 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Acme-Machi>
212  
213 =item * AnnoCPAN: Annotated CPAN documentation
214  
215 L<http://annocpan.org/dist/Acme-Machi>
216  
217 =item * CPAN Ratings
218  
219 L<http://cpanratings.perl.org/d/Acme-Machi>
220  
221 =item * Search CPAN
222  
223 L<http://search.cpan.org/dist/Acme-Machi/>
224  
225 =back
226  
227  
228 =head1 ACKNOWLEDGEMENTS
229  
230  
231 =head1 LICENSE AND COPYRIGHT
232  
233 Copyright 2016 Machi Amayadori.
234  
235 This program is free software; you can redistribute it and/or modify it
236 under the terms of the the Artistic License (2.0). You may obtain a
237 copy of the full license at:
238  
239 L<http://www.perlfoundation.org/artistic_license_2_0>
240  
241 Any use, modification, and distribution of the Standard or Modified
242 Versions is governed by this Artistic License. By using, modifying or
243 distributing the Package, you accept this license. Do not use, modify,
244 or distribute the Package, if you do not accept this license.
245  
246 If your Modified Version has been derived from a Modified Version made
247 by someone other than you, you are nevertheless required to ensure that
248 your Modified Version complies with the requirements of this license.
249  
250 This license does not grant you the right to use any trademark, service
251 mark, tradename, or logo of the Copyright Holder.
252  
253 This license includes the non-exclusive, worldwide, free-of-charge
254 patent license to make, have made, use, offer to sell, sell, import and
255 otherwise transfer the Package with respect to any patent claims
256 licensable by the Copyright Holder that are necessarily infringed by the
257 Package. If you institute patent litigation (including a cross-claim or
258 counterclaim) against any party alleging that the Package constitutes
259 direct or contributory patent infringement, then this Artistic License
260 to you shall terminate on the date that such litigation is filed.
261  
262 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
263 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
264 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
265 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
266 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
267 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
268 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
269 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270  
271  
272  
273 =head1 INSTALLATION
274  
275 To install this module, run the following commands:
276  
277 perl Build.PL
278 ./Build
279 ./Build test
280 ./Build install
281  
282  
283 After installing, you can find documentation for this module with the
284 perldoc command.
285  
286 perldoc Acme::Machi
287  
288 =cut
289 }
290 2 'END_MACHI'; # End of Acme::Machi
↑ Summary