Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 271 lines (188 sloc) 8.675 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
NAME
    perl5i - Bend Perl 5 so it fits how it works in our imaginations

SYNOPSIS
      use perl5i;

      or

      $ perl5i your_script.pl

DESCRIPTION
    THIS MODULE'S INTERFACE IS UNSTABLE! It's still a playground. Features
    may be added, changed and removed without notice. `use perl5i' may not
    even work in the future. See
    http://github.com/schwern/perl5i/issues/issue/69 and
    http://github.com/schwern/perl5i/issues/issue/60 for details. You have
    been warned.

    Perl 5 has a lot of warts. There's a lot of individual modules and
    techniques out there to fix those warts. perl5i aims to pull the best of
    them together into one module so you can turn them on all at once.

    This includes adding features, changing existing core functions and
    changing defaults. It will likely not be 100% backwards compatible with
    Perl 5, so perl5i will try to have a lexical effect.

    Please add to this imaginary world and help make it real, either by
    telling me what Perl looks like in your imagination
    (http://github.com/schwern/perl5i/issues or make a fork (forking on
    github is like a branch you control) and implement it yourself.

What it does
    perl5i enables each of these modules and adds/changes these functions.
    We'll provide a brief description here, but you should look at each of
    their documentation for full details.

  alias()
        alias( $name => $reference );
        alias( $package, $name => $reference );
        alias( @identifiers => $reference );

    Assigns a $refrence a $name. For example...

        alias foo => sub { 42 };
        print foo(); # prints 42

    It will also work on hash, array and scalar refs.

        our %stuff;
        alias stuff => \%some_other_hash;

    Multiple @identifiers will be joined with '::' and used as the fully
    qualified name for the alias.

        my $class = "Some::Class";
        my $name = "foo";
        alias $class, $name => sub { 99 };
        print Some::Class->foo; # prints 99

    If the $name has no "::" in it, the current caller will be prepended.

    This is basically a nicer way to say:

        no strict 'refs';
        *{$package . '::'. $name} = $reference;

  center()
        my $centered_string = $string->center($length);
        my $centered_string = $string->center($length, $character);

    Centers $string between $character. $centered_string will be of length
    $length.

    `<$character'> defaults to " ".

        say "Hello"->center(10); # " Hello ";
        say "Hello"->center(10, '-'); # "---Hello--";

    `<center()'> will never truncate `<$string'>. If $length is less than
    `<$string-'length>> it will just return `<$string'>.

        say "Hello"->center(4); # "Hello";

  wrap()
        my $wrapped = $string->wrap( width => $cols, separator => $sep );

    Wraps $string to width $cols, breaking lines at word boundries using
    separator $sep.

    If no width is given, $cols defaults to 76. Default line separator is
    the newline character "\n".

    See Text::Wrap for details.

  ltrim()
        my $string = ' testme'->ltrim; # 'testme'

    Trim leading whitespace (left).

  rtrim()
        my $string = 'testme '->rtrim; #'testme'

    Trim trailing whitespace (right).

  trim()
        my $string = ' testme '->trim; #'testme'

    Trim both leading and trailing whitespace.

  title_case()
        my $name = 'joe smith'->title_case; #Joe Smith

    Will uppercase every word character that follows a wordbreak character.

  die()
    `die' now always returns an exit code of 255 instead of trying to use
    `$!' or `$?' which makes the exit code unpredictable. If you want to
    exit with a message and a special exit code, use `warn' then `exit'.

  English
    English gives English names to the punctuation variables like `<$@'> is
    also `<$EVAL_ERROR'>. See perlvar for details.

    It does not load the regex variables which effect performance.
    `<$PREMATCH'>, `<$MATCH'>, and `<POSTMATCH'> will not exist. See `</p'>
    in perlre for a better alternative.

  Modern::Perl
    Turns on strict and warnings, enables all the 5.10 features like
    `given/when', `say' and `state', and enables C3 method resolution order.

  CLASS
    Provides `CLASS' and `$CLASS' alternatives to `__PACKAGE__'.

  File::chdir
    File::chdir gives you `$CWD' representing the current working directory
    and its assignable to `<chdir'>. You can also localize it to safely
    chdir inside a scope.

  File::stat
    File::stat causes `stat' to return objects rather than long arrays which
    you never remember which bit is which.

  DateTime
    `time', `localtime' and `gmtime' are replaced with DateTime objects.
    They will all act like the core functions.

        # Sat Jan 10 13:37:04 2004
        say scalar gmtime(2**30);

        # 2004
        say gmtime(2**30)->year;

        # 2009 (when this was written)
        say time->year;

  Time::y2038
    gmtime() and localtime() will now safely work with dates beyond the year
    2038 and before 1901 (the exact range is not defined, but its well into
    a couple million years in either direction).

  Module::Load
    Module::Load adds `load' which will load a module from a scalar without
    requiring you to do funny things like `eval require $module'.

  IO::Handle
    Turns filehandles into objects so you can call methods on them. The
    biggest one is `autoflush' rather than mucking around with `$|' and
    `select'.

        $fh->autoflush(1);

  autodie
    autodie causes system and file calls which can fail (`open', `system'
    and `chdir', for example) to die when they fail. This means you don't
    have to put `or die' at the end of every system call, but you do have to
    wrap it in an `eval' block if you want to trap the failure.

    autodie's default error messages are pretty smart.

    All of autodie will be turned on.

  autobox
    autobox allows methods to be defined for and called on most unblessed
    variables.

  autobox::Core
    autobox::Core wraps a lot of Perl's built in functions so they can be
    called as methods on unblessed variables. `@a->pop' for example.

  autobox::List::Util
    autobox::List::Util wraps the functions from List::Util (first, max,
    maxstr, min, minstr, shuffle, reduce, and sum) so they can be called on
    arrays and arrayrefs.

  autobox::dump
    autobox::dump defines a `perl' method that returns Data::Dumper style
    serialization of the results of the expression.

  autovivification
    autovivification fixes the bug/feature where this:

        $hash = {};
        $hash->{key1}{key2};

    Results in `<$hash-'{key1}>> coming into existance. That will no longer
    happen.

  Want
    Want generalizes the mechanism of the wantarray function, allowing a
    function to determine the context it's being called in. Want
    distinguishes not just scalar v. array context, but void, lvalue,
    rvalue, boolean, reference context and more. See perldoc Want.

BUGS
    Some parts are not lexical.

    See http://github.com/schwern/perl5i/issues/labels/bug for a complete
    list.

    Please report bugs at http://github.com/schwern/perl5i/issues/.

VERSIONING
    perl5i follows the Semantic Versioning policy, http://semver.org. In
    short...

    Versions will be of the form X.Y.Z.

    0.Y.Z may change anything at any time.

    Incrementing X (ie. 1.2.3 -> 2.0.0) indicates a backwards incompatible
    change.

    Incrementing Y (ie. 1.2.3 -> 1.3.0) indicates a new feature.

    Incrementing Z (ie. 1.2.3 -> 1.2.4) indicates a bug fix or other
    internal change.

NOTES
    Inspired by chromatic's Modern::Perl and in particular
    http://www.modernperlbooks.com/mt/2009/04/ugly-perl-a-lesson-in-the-impo
    rtance-of-language-design.html.

    I totally didn't come up with the "Perl 5 + i" joke. I think it was
    Damian Conway.

THANKS
    Thanks to our contributors: Chas Owens, Darian Patrick, rjbs, chromatic,
    Ben Hengst and anyone else I've forgotten.

    Thanks to Flavian and Matt Trout for their signature and Devel::Declare
    work.

    Thanks to all the CPAN authors upon whom this builds.

LICENSE
    Copyright 2009-2010, Michael G Schwern <schwern@pobox.com>

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

    See http://www.perl.com/perl/misc/Artistic.html

SEE ALSO
    Repository: http://github.com/schwern/perl5i/tree/master Issues/Bugs:
    http://github.com/schwern/perl5i/issues IRC: irc.perl.org on the #perl5i
    channel

    Modern::Perl

Something went wrong with that request. Please try again.