App-Pimpd
view release on metacpan or search on metacpan
lib/App/Pimpd/Validate.pm view on Meta::CPAN
}
}
sub to_terminal {
return (-t STDOUT) ? 1 : 0;
}
sub empty_playlist {
if(scalar($mpd->playlist->as_items) == 0) {
return 1;
}
return 0;
}
sub invalid_playlist_pos {
my @pos = @_;
my @playlist = map { $_ = $_->pos } $mpd->playlist->as_items;
my $fail = 0;
for(@pos) {
if($_ ~~ @playlist) {
# all good
}
else {
$fail++;
}
}
return($fail);
}
1;
__END__
=pod
=head1 NAME
App::Pimpd::Validate - Package exporting various functions for validating data
=head1 SYNOPSIS
use App::Pimpd;
use App::Pimpd::Validate;
if(to_terminal()) {
print "Yes, you can see me!\n";
}
$str = escape($str);
if(invalid_playlist_pos(42)) {
print STDERR "No song on playlist position 42!\n";
}
=head1 DESCRIPTION
App::Pimpd::Validate provides functions for verifying certain conditions that's
crucial for other functions.
=head1 EXPORTS
=over
=item remote_host()
Returns true if the MPD server is located on a remote host.
The MPD server is assumed to be remote if the B<mpd_host> configuration file
variable is:
not defined
or
equals 'localhost'
or
equals '127.0.0.1'
=item invalid_regex()
Parameters: $regex
Returns true if the provided regex is invalid.
=item empty_playlist()
Returns true if the current playlist is empty.
=item to_terminal()
Returns true if output is going to a TTY.
=item invalid_playlist_pos()
Parameters: $integer
Returns true if supplied argument is an invalid playlist position.
=item escape()
Parameters: $string
Returns: $string
Takes the supplied string and escapes it from evil chars the shell might
otherwise munch.
=item get_valid_lists()
Parameters: @playlists
Returns: @valid_playlists
Takes a list and traverses it, checking if every playlist exists.
If a playlist is found to be non-existant, tries to match the string against
all known playlists. If a partial match is found, prompts for validation.
=item isa_valid_playlist
=back
( run in 0.523 second using v1.01-cache-2.11-cpan-e1769b4cff6 )