evalempire / perl5i Goto Github PK
View Code? Open in Web Editor NEWA single module to fix as much of Perl 5 as possible in one go
Home Page: http://search.cpan.org/perldoc?perl5i
License: Other
A single module to fix as much of Perl 5 as possible in one go
Home Page: http://search.cpan.org/perldoc?perl5i
License: Other
Pull it from Algorithm::Numeric::Shuffle. People screw up shuffling all the time.
Instead of
no strict 'refs';
*{$package .'::'. $name} = sub { ... };
write
alias( $package .'::'. $name, sub { ... } );
http://www.rubycentral.com/pickaxe/ref_c_string.html#String.center
$word = "Hello";
$word->center(20) = " hello ";
Wrap to X columns. use Text::Wrap
Use an overloaded object which boolifies to true/false but numifies to the exit code. This will let if( system("...") ) work but also let if( system("...") == 0 ) still work.
I think you mean File::Stat? Not sure what version you want.
The datetime.t test seems to be missing from the repository.
Though some of the method names could use some work. Like natatime().
uniq, zip, any, all, none, true, false are all nice.
Like in Ruby.
read $file {
print;
}
The bin/perl5i.PL script currently generates a *nix sell script that invokes perl with perl5i niceties. Something similar is needed for Windows, likely using a .bat file or something. Schwern mentioned pl2bat from Module::Build as a possible solution.
All that getpwuid and junk.
Uppercase each word in a string.
Document the existence of the perl5i utility in the module and also provide some POD in the thing itself.
Somehow integrate local::lib to solve the problem of locally installed modules
It might be a good idea to have a source filter to change
local @CWD;
into
local $CWD;
or at least throw a warning.
An improved configuration for the CPAN shell. It will ask one question "do you want to install for yourself or for the whole system" and then configure everything for you. Then it will ask "do you want detailed configuration?" with a default of "no". That's it. You will have a working, configured CPAN shell.
Stuff for merging hashes and flattening hashes.
Time::y2038 doesn't play nice with Time::Piece. They both want to override localtime and gmtime. Worse, Time::Piece will use CORE::localtime and CORE::gmtime so it won't see Time::y2038.
And they don't warn!
$ time perl -wle 'use perl5i; print scalar gmtime 248-246-245+244-243+242-241-240'
Mon Jan 3 06:09:04 -5868930
$ time perl -wle 'use perl5i; print scalar gmtime 248-246-245+244-243+242-241-240-2**39'
Sat Dec 28 17:50:56 5872869
To allow chaining
File::Slurp is the obvious candidate. I also like that it can write_file() in one go.
Perl6::Slurp is far more complete, but it doesn't write files, its way more complicated and its scary, old, unmaintained Damian-ware. Perhaps the solution is to enhance File::Slurp with Perl6::Slurp features.
Finally, a solution to the "how do I insert a line in the middle of a file" would be nice. That can be served by the excellent and efficient Tie::File but with a sprinkling of sugar so the user isn't exposed to a tie() call. They just get an array (or array ref or object acting like an array ref).
touch
recursive rm
mv and cp allowing multiple source files to a directory
mkdir -p
Crib from ExtUtils::Command and Shell::Command.
MooseX::Declare is sexy. It also solves the problem of Moose load time since it can lazy load when class() is called.
Might it be handy to load that? Maybe make %RE load Regexp::Common on demand.
Now that we have autobox, add in a method to dump any variable. autobox::Core may already have this.
Like in Ruby.
@foo = map { |$var| $var++ } @bar;
to be equivalent to
@foo = map { $_++ } @bar;
Perhaps using Data::Bind?
Rather than having to muck with File::Spec.
Path::Class?
Much of perl5i is not lexical. Muck with %^H to make it so. Tests in t/lexical.t
File::stat will cause stat() to always return an object. It should be trivial to make it return the traditional list of stuff in array context, or to overload the object. This will make it backwards compatible.
Something to make changing directory lexical.
File::chdir? File::pushd?
Add something to smooth out cross platform issues with running programs.
IPC::Cmd? IPC::Run?
This thing is going to get pretty fat pretty fast. It would be nice if it delayed loading of modules for as long as possible.
Things like File::stat and Time::Piece that only export a handful of functions can be wrapped in autoloading functions. Just benchmark before hand to see if it helps load time to actually remove them. A lot of the cost of loading a module in isolation is actually loading very common modules (strict, Exporter, base...) which will be loaded anyway.
Jesse Wolfe is annoyed that he can't put objects/references in hash keys. I don't know if there's a way to do this without patching core, but it sure would be nice
It looks like the slowness is in DateTime->set_time_zone(). It starts to get noticeably slower after 2038.
force anything in to list context
eq_or_diff( [flat([[{this =>{is => [qw{a test}]}}])], [qw{this is a test}] )
Like stat() and localtime()
The latest version of DateTime in CPAN is 0.47, but you are requiring 1.12.
trim (strip whitespace), ltrim, rtrim
is a number
is an integer, decimal... all the stuff from perlfaq4
is a regex
is an object/instance
is a reference
I hate typing use Data::Dumper; warn Dumper [ $foo ].
Optionally, rename it to dump().
And they don't warn!
$ time perl -wle 'use perl5i; print scalar gmtime 2**48-2**46-2**45+2**44-2**43+2**42-2**41-2**40'
Mon Jan 3 06:09:04 -5868930
$ time perl -wle 'use perl5i; print scalar gmtime 2**48-2**46-2**45+2**44-2**43+2**42-2**41-2**40-2**39'
Sat Dec 28 17:50:56 5872869
One pain I have seen people have is the lack of a trim function. I have seen numerous CompanyName::Util modules with weird/bad/ugly trim functions. The problem with trim though is its lack of definition: should it trim on the left, on the right, or both; should it trim spaces, whitespace, or custom character classe; should it modify the string or return a copy; etc. Normally the right answer (in my opinion) is to use a substitution written for that specific case, but people seem resistant to that (and they do have some good arguments). I think we should provide a scalar trim method with the following arguments:
is "\tfoo "->trim, "foo", "default removes whitespace on both sides, does not modify string";
is "\tfoo "->trim(" "), "\tfoo", "sinlge arg is character to remove";
is "\tfoo "->trim("[f \t]"), "oo", "single arg can be a character class";
is "\tfoo "->trim('\s'), "foo", "sinlge arg can be a shorthand character class";
is "\tfoo "->trim(left => '\s'), "foo ", "multiple args are a named paramters, in this case trim on the left";
is "\tfoo "->ltrim, "foo ", "trim on the left (TIMTOWTDI);
not_ok eval { "\tfoo "->ltrim(right => '\s'); 1 }, "left trim croaks if asked to trim on the right";
is $@, "probable misuse of ltrim", "ltrim croaks with this error message";
not_ok eval { "\tfoo "->trim(both => '\s'); 1 }, "left trim croaks if asked to trim both";
is $@, "probable misuse of ltrim", "ltrim croaks with this error message";
is "\tfoo "->trim(right => '\s'), "\tfoo", "trim on the right";
is "\tfoo "->rtrim, "\tfoo", "trim on the right ("TIMTOWTDI");
not_ok eval { "\tfoo "->rtrim(left => '\s'); 1 }, "right trim croaks if asked to trim on the left";
is $@, "probable misuse of rtrim", "rtrim croaks with this error message";
not_ok eval { "\tfoo "->trim(both => '\s'); 1 }, "right trim croaks if asked to trim both";
is $@, "probable misuse of ltrim", "rtrim croaks with this error message";
is "\tfoo "->trim(both => '\s'), "foo", "trim on both";
is "\tfoo "->trim(left => '\s', right => '\s'), "foo", "trim on both (TIMTOWTDI)";
my $foo = "\tfoo ";
is $foo->(inplace => 'true'), "foo", "if left, right, or both is not set default to both";
is $foo, "foo", "inplace attempts to change the scalar";
not_ok eval { "\tfoo "->trim(inplace => 1); 1 }, "inplace croaks if it can't modify the string";
ok $@ =~ qr/trim could not modify scalar/, "it croaks with this error message";
alias my $foo => \$bar;
would be spiffy. Data::Alias would do that, but its kinda broken on bleadperl.
Instead of
for my $key (keys %hash) {
my $value = $hash{$key};
....
}
I want
for my($key, $value) (%hash) {
...
}
Or something. Also working for pairs in lists. Extend it out to work for any number of elements.
Use DateTime instead of Time::Piece. Write gmtime() and localtime() to return DateTime objects which stringify to emulate ctime. This may eliminate the need for Time::y2038.
Would it be helpful to automatically use mylib to have an absolute path to /path/which/contains/program/lib ?
Incorporate subroutine and method signatures.
We needs some. Carp is the obvious choice. Is there a better one?
I don't know if this is a bug in perl5i or the modules it uses, but I needed to install the following modules to get the tests to pass (even though perl Build.PL said everything was okay):
Time-Piece.t - IPC::System::Simple
Module-Load.t - Text::ParseWords
modern-perl.t - Array::Compare
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.