Bashor has moved to GitLab: https://gitlab.com/killmag10/bashor
This repository on GitHub will not be updated any more. Use the GitLab repository.
Bashor is a pseudo object oriented framwork for the bash.
Bashor is a alternate way to use object orientation in a filesystem close programming language (Bash), to write structered scripts with many file operations what have no big attention to performance. If you have attention to performance use nodejs. :p
- Create classes.
- Create objects.
- Inherit classes.
- Autoloading classes.
- Serialization of objects.
- Basic classes includet.
- Profiling.
- Code coverage report (Bashor_Code_Coverage).
Include bashor in your main script file.
BASE_DIR=`printf '%s' "$BASH_SOURCE" | sed 's#/\?[^/]*$##' | sed 's#^./##'`;
if [[ ! "$BASE_DIR" =~ ^/ ]]; then
BASE_DIR=`printf '%s' "$PWD/$BASE_DIR" | sed 's#/\.\?$##'`;
fi
. "$BASE_DIR/loader.sh";
For the API Documentation run:
make man
Set the environment variable BASHOR_PATH_CONFIG to load this as config script.
Add your class paths to BASHOR_PATH seperate with ':'.
- BASHOR_CLASS_AUTOLOAD : Autoloading
- '' : Autoloading inactive
- '1' : Autoloading active (default)
- BASHOR_CODEING_METHOD : Internal coding method.
- base64 (default)
- hex
- BASHOR_BASE64_USE : Programm used for base64 coding.
- openssl
- perl
- base64 (default)
- BASHOR_USE_GETOPT : Use getopt for parameter reading.
- '' : Use getopts.
- '1' : Use getopt. (default)
- BASHOR_COMPATIBILITY_THIS : Use this instat of static.
- '' : Off. (default)
- '1' : On.
- BASHOR_INTERACTIVE : Use interactive mode.
- '' : Off. (default)
- '1' : On.
- BASHOR_ERROR_CLASS : Use Bashor_ErrorHandler class for error handling.
- '' : Off.
- '1' : On. (default)
The profiling format is valgrind (You can view it with kcachgrind).
- BASHOR_PROFILE : Use profiling.
- '' : Off. (default)
- '1' : On.
- BASHOR_PROFILE_FILE : File path to save profiling.
This is an example how you can use the code coverage:
new Bashor_Code_Coverage_Writer_Html CoverageWriter "$BASE_DIR/../codeCoverage"
class Bashor_Code_Coverage setVerbose '1'
class Bashor_Code_Coverage start "$BASE_DIR/../"
...
# your code
...
class Bashor_Code_Coverage stop "$CoverageWriter"
Example:
new Bashor_List Data
object "$Data" set "test" "blub 123blub"
res=`object "$Data" get "test"`
remove "$Data"
- Function Name:
- "CLASS_"
- Your class name. Folders seperated by "_".
- "_" + Method name.
- Protected starts with an extra "_" (tow with normal seperator).
- Magic methods starts with "__" (three with normal seperator).
- __load : Called on class loding (For static variables).
- __construct : Called on object creation (new).
- __destruct : Called on object destruction (remove).
- __sleep : Called on object serialization (serialize).
- __wakeup : Called on object unserialization (unserialize).
##
# Loader
#
# Called on class loding
CLASS_Class___load()
{
requireStatic
return 0
}
##
# Constructor
#
# Called on object creation (new)
CLASS_Class___construct()
{
requireObject
return 0
}
##
# Destructor
#
# Called on object destruction (remove)
CLASS_Class___destruct()
{
requireObject
return 0
}
##
# Make object ready for sleep.
#
# Called on object serialization (serialize)
CLASS_Class___sleep()
{
requireObject
return 0
}
##
# Make object ready for wakeup.
#
# Called on object unserialization (unserialize)
CLASS_Class___wakeup()
{
requireObject
return 0
}
##
# Check if the class has the over given method.
#
# $1 string method name
# $? 0:OK
# $? 1:ERROR
CLASS_Class_hasMethod()
{
requireParams R "$@"
issetFunction CLASS_"$CLASS_TOP_NAME"_"$1"
return $?
}
To run the tests run:
make test