# Copyright 2013,2014 Dakota Simonds # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use warnings; use strict; sub EXIT_SUCCESS (){ #C style 1; } sub TRUE (){ 1; } sub FALSE (){ 0; } sub forceflush{ our $| = 1; return EXIT_SUCCESS; } sub savefile{ #savefile(filename, data); my $SVFL; open $SVFL, ">>", $_[0]; syswrite $SVFL, $_[1]; close $SVFL; return EXIT_SUCCESS; } sub assert{ #C style my @assertions = @_; foreach my $testAssertion (@assertions){ if( not eval $testAssertion ){ print "Assertion failure: '$testAssertion'\n"; exit 0; } #else{ print "win\n"; } } return EXIT_SUCCESS; } sub prompt{ my $question = shift; my $style = shift; my $styleOut; my $input; my %styles=( plain => "\x20", normal => ': ', yn => ' (y/n) ? ', ); if($style eq ""){ $styleOut = $styles{"plain"}; } else{ $styleOut = $styles{$style}; } { #these currlies makes redo work when input is not valid print $question, $styleOut; $input = ; chomp $input; if(not $input =~ m/(y|n)/i and $style eq "yn"){ print "\nThat is not a valid input!\n"; redo; } } return $input; } sub strcat{ my $compiled; for my $str (@_) { $compiled = $compiled . $str; } return $compiled; } sub longCatIsLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonnngggggg{ return ''; } 1; __END__ =head1 NAME Spice =head1 SYNOPSIS technically all these are functions but these three return true or false and take no arguments. meant to reduce magic numbers. EXIT_SUCCESS - C style return (true) TRUE - returns 1 FALSE - returns 0 forceflush - same as $|=1 savefile - appends data to a file assert - C style fuction. Like eval but if code reurns a false the program exits otherwise returns 1. takes a list. prompt - get input in one line strcat - a funtion the concatinates it's inputs savefile - writes to a file in one line =head1 DESCRIPTION Simple PERL module to that fixes small anoying things and provides a bit of C style funtionality =head1 EXAMPLES forceflush; while( TRUE ){ do something } savefile("meows.txt", "data"); if($foobar == FALSE){ do something } prompt("keywords","normal"); prompt("do you want a cookie", "yn"); prompt("do you want a cookie (Y/n)?", "plain"); assert('$a=1'); savefile($filename, $data); return EXIT_SUCCESS; =cut