Venus - OO Library
OO Standard Library for Perl 5
0.01
package main; use Venus qw( catch error raise ); # error handling my ($error, $result) = catch { error; }; # boolean keywords if ($result and $result eq false) { true; } # raise exceptions if (false) { raise 'MyApp::Error'; } # and much more! true ne false;
This library provides an object-orientation framework and extendible standard library for Perl 5, built on top of Moo with classes which wrap most native Perl data types. Venus has a simple modular architecture, robust library of classes and methods, supports pure-Perl autoboxing, advanced exception handling, "true" and "false" keywords, package introspection, command-line options parsing, and more. This package will always automatically exports true and false keyword functions (unless existing routines of the same name already exist in the calling package), otherwise exports keyword functions as requested at import.
true
false
This package provides the following functions:
catch(CodeRef $block) (Error, Any)
The catch function executes the code block trapping errors and returning the caught exception in scalar context, and also returning the result as a second argument in list context.
Since 0.01
package main; use Venus 'catch'; my $error = catch {die}; $error; # 'Died at ...'
package main; use Venus 'catch'; my ($error, $result) = catch {error}; $error; # Venus::Error
package main; use Venus 'catch'; my ($error, $result) = catch {true}; $result; # 1
error(Maybe[HashRef] $args) (Error)
The error function throws a Venus::Error exception object using the exception object arguments provided.
package main; use Venus 'error'; my $error = error;
package main; use Venus 'error'; my $error = error { message => 'Something failed!', };
false() (Bool)
The false function returns a falsy boolean value which is designed to be practically indistinguishable from the conventional numerical 0 value.
0
package main; use Venus; my $false = false;
package main; use Venus; my $true = !false;
raise(Str $class | Tuple[Str, Str] $class, Maybe[HashRef] $args) (Error)
The raise function generates and throws a named exception object derived from Venus::Error, or provided base class, using the exception object arguments provided.
package main; use Venus 'raise'; my $error = raise 'MyApp::Error';
package main; use Venus 'raise'; my $error = raise ['MyApp::Error', 'Venus::Error'];
package main; use Venus 'raise'; my $error = raise ['MyApp::Error', 'Venus::Error'], { message => 'Something failed!', };
true() (Bool)
The true function returns a truthy boolean value which is designed to be practically indistinguishable from the conventional numerical 1 value.
1
package main; use Venus; my $true = true;
package main; use Venus; my $false = !true;
This package provides the following features:
This library provides a Perl object-oriented standard library with value classes and consistently named methods.
example 1
package main; use Venus::Array; my $array = Venus::Array->new([1..4]); # $array->all(sub{ $_ > 0 }); # $array->any(sub{ $_ > 0 }); # $array->each(sub{ $_ > 0 }); # $array->grep(sub{ $_ > 0 }); # $array->map(sub{ $_ > 0 }); # $array->none(sub{ $_ < 0 }); # $array->one(sub{ $_ == 0 }); # $array->random; use Venus::Hash; my $hash = Venus::Hash->new({1..8}); # $hash->all(sub{ $_ > 0 }); # $hash->any(sub{ $_ > 0 }); # $hash->each(sub{ $_ > 0 }); # $hash->grep(sub{ $_ > 0 }); # $hash->map(sub{ $_ > 0 }); # $hash->none(sub{ $_ < 0 }); # $hash->one(sub{ $_ == 0 }); # $hash->random; $array->count == $hash->count;
This library provides value classes which wrap native Perl data types and provides methods for operating their values.
package main; use Venus::Array; my $array = Venus::Array->new;
example 2
package main; use Venus::Boolean; my $boolean = Venus::Boolean->new;
example 3
package main; use Venus::Code; my $code = Venus::Code->new;
example 4
package main; use Venus::Float; my $float = Venus::Float->new;
example 5
package main; use Venus::Hash; my $hash = Venus::Hash->new;
example 6
package main; use Venus::Number; my $number = Venus::Number->new;
example 7
package main; use Venus::Regexp; my $regexp = Venus::Regexp->new;
example 8
package main; use Venus::Scalar; my $scalar = Venus::Scalar->new;
example 9
package main; use Venus::String; my $string = Venus::String->new;
example 10
package main; use Venus::Undef; my $undef = Venus::Undef->new;
This library provides opt-in pure Perl autoboxing allowing you to chain methods calls across objects and values.
package main; use Venus::String; my $string = Venus::String->new('hello, world'); $string->box->split(', ')->join(' ')->titlecase->unbox->get; # Hello World
This library provides serveral essential utility classes for performing common programming tasks.
package main; use Venus::Args; my $args = Venus::Args->new;
package main; use Venus::Box; my $box = Venus::Box->new;
package main; use Venus::Data; my $docs = Venus::Data->new->docs;
package main; use Venus::Date; my $date = Venus::Date->new;
package main; use Venus::Error; my $error = Venus::Error->new;
package main; use Venus::Json; my $json = Venus::Json->new;
package main; use Venus::Name; my $name = Venus::Name->new;
package main; use Venus::Opts; my $opts = Venus::Opts->new;
package main; use Venus::Path; my $path = Venus::Path->new;
package main; use Venus::Data; my $text = Venus::Data->new->text;
example 11
package main; use Venus::Space; my $space = Venus::Space->new;
example 12
package main; use Venus::Throw; my $throw = Venus::Throw->new;
example 13
package main; use Venus::Try; my $try = Venus::Try->new;
example 14
package main; use Venus::Type; my $type = Venus::Type->new;
example 15
package main; use Venus::Vars; my $vars = Venus::Vars->new;
This library provides a package reflection class, Venus::Space, which can be used to perform meta-programming on package spaces.
package main; use Venus::Space; my $space = Venus::Space->new('Venus'); $space->do('tryload')->routines;
This library provides a framework for raising, i.e. generating and throwing, exception objects and catching them.
package MyApp; use Venus::Class; with 'Venus::Role::Throwable'; with 'Venus::Role::Catchable'; sub execute { my ($self) = @_; $self->throw->error; } package main; my $myapp = MyApp->new; $myapp->catch('execute'); # catch MyApp::Error
This library provides a library of composable roles which can be used to extend core behaviors to custom objects.
package MyApp; use Venus::Class; with 'Venus::Role::Dumpable'; with 'Venus::Role::Stashable'; package main; my $myapp = MyApp->new; $myapp->stash(greeting => 'hello world'); $myapp->dump('stash'); # '{"greeting" => "hello world"}'
This library provides a mechanism for extending the standard library, i.e. value classes, using plugins which can be automatically discovered and invoked. (no monkey-patching necessary)
package Venus::String::Plugin::Base64; sub new { return bless {}; } sub execute { my ($self, $string, @args) = @_; require MIME::Base64; return MIME::Base64::encode_base64($string->value); } package main; use Venus::String; my $string = Venus::String->new('hello, world'); $string->base64;
Cpanery, cpanery@cpan.org
cpanery@cpan.org
Copyright (C) 2021, Cpanery
Read the "license" file.
https://venus.cpanery.com
https://github.com/cpanery/venus/wiki
https://github.com/cpanery/venus/issues
https://cpanery.com
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.