Acme-Machi
view release on metacpan or search on metacpan
lib/Acme/Machi.pm view on Meta::CPAN
my $words_list = $_[0]{Words};
($_[1] // *STDOUT)->print( $_[0]->name(),": ", $words_list->[int(rand($#$words_list))], "\n");
}
=head2 search_file_from
Using BFS or DFS to search the target from certain directory.
Return: a two-element list:
the first element is boolean value denoting whether the target was found or not.
the second element is the result string outputed from the core module, Data::Dumper.
You may get to know files distribution even better after printing the string.
=cut
sub search_file_from {
ref $_[0] || croak "Oops! Cannot ask non-human to search!";
my ($target, $dir, $RESP) = @_[1,2,3];
my $obj = File::Spec->catfile(getcwd, $target);
my $s_dir = File::Spec->catfile(getcwd, $dir);
my $push_front_back = ($_[0]->habit() eq 'DFS')?
sub {
t/Acme-Machi.t view on Meta::CPAN
if ok(defined &Acme::Machi::new, 'Acme::Machi::new is defined');
can_ok($loli, $_) for qw/named learning affectionate search_file_from/;
}
# -----------------------------------------------------------------------------
diag(" Test functionality of Acme::Machi->new() method");
# -----------------------------------------------------------------------------
METHOD_NEW: {;
my $loli_first = Acme::Machi->new();
my $loli_second = Acme::Machi->new('Megu');
# Initial value check
#############################################################
isa_ok($loli_first, 'Acme::Machi');
isa_ok($loli_second, 'Acme::Machi');
like($loli_first->name(), qr/\bMachi\b/, 'Default \'Name\' is set');
like($loli_second->name(), qr/\bMegu\b/,
'Constructor can modify \'Name\' instance variable');
open my $fh, '>', \ my $my_string;
$loli_first->affectionate($fh);
ok($my_string =~ qr/starving/, 'Default \'Words\' is set');
like($loli_second->habit(), qr/[DB]FS/, 'Default \'SRCH_Habit\' is set');
#############################################################
# Cannot use instance method to construct object
#############################################################
{
local $@;
isnt(eval{$loli_first->new(); 1}, 1, 'caller test')
&& like($@, qr/cannot.+?instance method.+/i, 'Die with a pre-defined error msg');
}
#############################################################
# Cannot change one's habit with undefined key word
#############################################################
$loli_second->have_the_habit_of('Smily_Search');
like($loli_second->habit(), qr/[DB]FS/,
'Except for \'DFS\' & \'BFS\', the others are ignored.');
#############################################################
}
# -----------------------------------------------------------------------------
diag(" Test functionality of affectionate() method");
# -----------------------------------------------------------------------------
METHOD_AFFECTIONATE: {;
( run in 0.618 second using v1.01-cache-2.11-cpan-39bf76dae61 )