Acme-Machi
view release on metacpan or search on metacpan
lib/Acme/Machi.pm view on Meta::CPAN
use warnings;
use IO::Dir;
use File::Spec;
use File::Basename;
use Data::Dumper;
use Cwd;
use Carp;
#import CPAN libs
use namespace::autoclean;
=head1 NAME
Machi - Awesome Machi here!
=head1 VERSION
Version v1.00.1
=cut
=head1 SYNOPSIS
Quick summary of what the module does.
Exactly a little code snippet.
use Acme::Machi;
my $loli = Acme::Machi->new( $name ); # Give birth to a person; accept an optional argument to set the person's name.
$loli->named( $name ); # Name the person. Default name is 'Machi'.
$loli->name(); # Get person's name.
$loli->have_the_habit_of( $habit ); # Person gets into certain searching habit.
$loli->habit(); # Get one's searching habit.
$loli->learning( @words ); # Teach the person saying something endearing.
$loli->affectionate( $file_handle ); # The person shall randomly tell about what you previously teached her/him to say.
$loli->search_file_from( $target, $dir, $RESP ); # Search file/dir from certain spcified directory using BFS or DFS.
# The third argument $RESP representing 'Responsible', which means she/he will
# stop searching and come back in a moment when finding the target one.
# In case $RESP is in zero state or $RESP is set but the target isn't found,
# she/he will finally print out the tree-like structure of your file system
# before coming back in despair.
=head1 METHODS
=head2 new
Create a Machi-type instance.
=cut
sub new {
(ref $_[0]) && croak "Oops! Cannot use instance method to construt an object!";
bless {
Name => $_[1] // "Machi",
Words => ["I am starving!!"], # In general, creatures always know how to express their hunger.
SRCH_Habit => 'BFS',
}, $_[0];
}
=head2 named
Assign a new value to scalar-type instance variable, 'Name', in the object.
Return: value of assignment.
=cut
sub named {
(ref $_[0]) || croak "Oops! Cannot use class method setting the object!";
$_[0]{Name} = $_[1];
}
=head2 name
Return: person's name.
=cut
sub name {
$_[0]{Name};
}
=head2 have_the_habit_of
Assign a new searching habit to scalar-type instance variable, 'SRCH_Habit'.
Only strings 'BFS' and 'DFS' are valid, setting the others will be ignored.
Return: value of assignment.
=cut
sub have_the_habit_of {
(ref $_[0]) || croak "Oops! Cannot use class method setting the object!";
$_[0]{SRCH_Habit} = $_[1] if($_[1] =~ m/([DB]FS)/);
}
=head2 habit
Return: person's searching habit.
=cut
sub habit {
$_[0]{SRCH_Habit};
}
=head2 learning
Append a list of words to array-type instance variable, 'Words', in the object.
Return: how many words have she/he learnt.
=cut
sub learning {
(ref $_[0]) || croak "Oops! Cannot use class method setting the object!";
unshift (@{$_[0]{Words}}, @_[1 .. $#_]);
}
( run in 2.944 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )