NAME

perl5::tobyink - a lightweight collection of syntax extensions

SYNOPSIS

use perl5::tobyink;

DESCRIPTION

use perl5::tobyink is roughly equivalent to:

use 5.010;
use autodie;
use common::sense;
use constant { false => !1, true => !!1 };
use mro qw(c3);
use namespace::sweep;
use syntax qw(maybe perform ql qwa);
use true;
use utf8::all;

no indirect qw(:fatal);

require Encode;
require IO::Handle;

use Carp qw(carp croak confess);
use Devel::Assert qw(0);
use List::Util qw(first max min reduce shuffle);
use List::MoreUtils qw(uniq);
use Method::Signatures::Simple 1.00 method_keyword => 'method', function_keyword => 'function';
use Object::Tap -package => 'UNIVERSAL';
use Path::Class qw(file dir);
use POSIX qw(floor ceil);
use Scalar::Util qw(blessed isweak looks_like_number refaddr reftype weaken);
use Try::Tiny 0;

*trim      = \&perl5::tobyink::trim;
*ltrim     = \&perl5::tobyink::ltrim;
*rtrim     = \&perl5::tobyink::rtrim;
*normalize = \&perl5::tobyink::normalize;

Object Oriented Programming

Calling with the parameter "-class", will also act as use Any::Mo, and thus will set up a new method for your package, provide has, extends and other antlery sugar.

{
    package Person;
    use perl5::tobyink -class;
    has name => (is => read_only, isa => 'Str');
    has age  => (is => read_only, isa => 'Num');
}

With the "-class" parameter, additional constants read_only and read_write are exported too.

If you'd rather use Moose or Mouse or whatever, then don't pass "-class" and use Moose/Mouse/whatever manually. The read_only/read_write constants can be exported using the "-antlers" parameter.

{
    package Person;
    use perl5::tobyink -antlers;
    use Any::Moose;
    has name => (is => read_only, isa => 'Str');
    has age  => (is => read_only, isa => 'Num');
} 

Assertions

You can include assertions in your code a la:

method set_name ($new)
{
    assert(length $new > 0);
    $self->{name} = $new;
}

By default assertions are not checked at all; they are short-circuited entirely. To have them checked, you need to use Devel::Assert -all. One easy way is to run your script like this:

perl -MDevel::Assert=-all yourscript.pl

BUGS

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=perl5-tobyink.

SEE ALSO

Any::Mo, autodie, Carp, common::sense, Encode, Devel::Assert, indirect, IO::Handle, List::Util, List::MoreUtils, Method::Signatures::Simple, mro, namespace::sweep, Object::Tap, Path::Class, POSIX, Scalar::Util, Syntax::Feature::Maybe, Syntax::Feature::Perform, Syntax::Feature::Ql, Syntax::Feature::Qwa, true Try::Tiny, utf8::all.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2012 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.