Venus - Object-Oriented Standard Library for Perl 5
Venus is 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.
Demo: Better Boolean Values
i.e. Venus knows the difference between boolean 0
, numerical 0
, and the
string '0'
.
Installation
Install Venus using cpm:
cpm install Venus
Install Venus using cpanm:
cpanm -qn Venus
Install Venus using Perl:
$ curl -L https://cpanmin.us | perl - -qn Venus
Install Venus using Perl (from GitHub):
$ curl -ssL https://cpanmin.us | perl - -qn git://github.com/cpanery/venus.git
Features
- One Dependency
- Standard Library
- Value Classes
- Builtin Autoboxing
- Utility Classes
- Package Reflection
- Exception Handling
- Composable Standards
- Pluggable Library
- Robust Documentation
Feature: Standard Library
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;
Feature: Value Classes
Array
package main;
use Venus::Array;
my $array = Venus::Array->new;
$array->random;
Boolean
package main;
use Venus::Boolean;
my $boolean = Venus::Boolean->new;
$boolean->negate;
Code
package main;
use Venus::Code;
my $code = Venus::Code->new;
$code->call;
Hash
package main;
use Venus::Hash;
my $hash = Venus::Hash->new;
$hash->random;
Feature: Builtin Autoboxing
package main;
use Venus::String;
my $string = Venus::String->new('hello, world');
$string->box->split(', ')->join(' ')->titlecase->unbox->get;
# Hello World
Feature: Utility Classes
Args
package main;
use Venus::Args;
my $args = Venus::Args->new;
$args->get(0);
Data
package main;
use Venus::Data;
my $docs = Venus::Data->new->docs;
$docs->find('head1', 'NAME');
Date
package main;
use Venus::Date;
my $date = Venus::Date->new;
$date->iso8601;
Error
package main;
use Venus::Error;
my $error = Venus::Error->new;
$error->throw;
Path
package main;
use Venus::Path;
my $path = Venus::Path->new('/tmp/random');
$path->mkdirs;
Feature: Package Reflection
package main;
use Venus::Space;
my $space = Venus::Space->new('Venus');
$space->do('tryload')->routines;
Feature: Exception Handling
package MyApp;
use Venus::Class;
with 'Venus::Role::Throwable';
with 'Venus::Role::Catchable';
sub execute {
shift->throw->error;
}
package main;
my $myapp = MyApp->new;
my $error = $myapp->catch('execute');
# $error->isa('MyApp::Error');
Feature: Composable Standards
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"}'
Feature: Pluggable Library
package Venus::String::Plugin::Base64;
use Venus::Class;
sub execute {
my ($self, $string) = @_;
require MIME::Base64;
return MIME::Base64::encode_base64($string->value);
}
package main;
use Venus::String;
my $string = Venus::String->new('hello, world');
$string->base64;
Feature: Template System
package main;
use Venus::Template;
my $template = Venus::Template->new(q(
{{ if user.name }}
Welcome, {{ user.name }}!
{{ else user.name }}
Welcome, friend!
{{ end user.name }}
));
$template->render;
Documentation
For documentation and usage information on specific classes or roles (traits), see below:
- Venus
- Venus::Args
- Venus::Array
- Venus::Boolean
- Venus::Box
- Venus::Class
- Venus::Code
- Venus::Data
- Venus::Date
- Venus::Error
- Venus::Float
- Venus::Hash
- Venus::Json
- Venus::Kind
- Venus::Kind::Utility
- Venus::Kind::Value
- Venus::Match
- Venus::Name
- Venus::Number
- Venus::Opts
- Venus::Path
- Venus::Process
- Venus::Regexp
- Venus::Replace
- Venus::Role
- Venus::Role::Accessible
- Venus::Role::Boxable
- Venus::Role::Buildable
- Venus::Role::Catchable
- Venus::Role::Coercible
- Venus::Role::Digestable
- Venus::Role::Doable
- Venus::Role::Dumpable
- Venus::Role::Explainable
- Venus::Role::Mappable
- Venus::Role::Matchable
- Venus::Role::Pluggable
- Venus::Role::Printable
- Venus::Role::Proxyable
- Venus::Role::Stashable
- Venus::Role::Throwable
- Venus::Role::Tryable
- Venus::Role::Valuable
- Venus::Scalar
- Venus::Search
- Venus::Space
- Venus::String
- Venus::Template
- Venus::Throw
- Venus::Try
- Venus::Type
- Venus::Undef
- Venus::Vars
- Venus::Yaml
Founder
Contributing
We rely on your contributions and feedback to improve Venus, and we love hearing about your experiences and what we can improve upon.
All contributions are always welcome! See the contributing guide for ways to get started, and please adhere to this project's code of conduct.
Support
For support, feel free to report an issue.