Actions from Graham KnopMovable Type Pro 4.382016-10-25T17:52:26Zhttp://blogs.perl.org/mt/mt-cp.fcgi?__mode=feed&_type=actions&blog_id=0&id=437Commented on Paging TOBYINK in Lee Jtag:blogs.perl.org,2016:/users/lee_j//645.7756#17522972016-10-25T16:52:26ZGraham Knop
I'd be interested in seeing your benchmark script to see what you are actually comparing, as some of the numbers seem a bit odd. Also note that MooX::TypeTiny exists and should make the combination of Moo and Type::Tiny as fast as is possible in pure perl. It may be time to bake that in to Moo.

Regarding module maintenance, I had previously tried reaching out about getting comaint or first-come Type::Tiny and some of Toby's other modules. I didn't get any response at the time. We'd definitely be interested in getting Type::Tiny and Toby's other Type- and MooX- dists moved into an org on github (possible the Moose org) and some comaints added so improvements can be shipped easier.

]]>
Commented on Reply to David Golden "Comparison of Class::Tiny and Object::Simple" in Yuki Kimoto Perl Blogtag:blogs.perl.org,2016:/users/yuki_kimoto//2020.7657#17342382016-09-09T13:34:16ZGraham Knop
David Golden is not the p5p pumpking.]]>
Commented on Missing Smart Match in JT Smithtag:blogs.perl.org,2016:/users/jt_smith//242.7543#17127582016-06-21T00:45:43ZGraham Knop
I don't find

$x in @a

very comprehensible because it isn't obvious how it will be comparing elements. Will it use string equality or numeric equality? What if you need to pick one or the other?]]>
Commented on Missing Smart Match in JT Smithtag:blogs.perl.org,2016:/users/jt_smith//242.7543#17116542016-06-16T17:55:11ZGraham Knop
Trying to use looks_like_number to "fix" my example means that "01" ~~ "1" would return true. That is currently not the case. There are other similar cases that are more subtle. It just can't be done properly with perl's untyped variables.]]>
Commented on Missing Smart Match in JT Smithtag:blogs.perl.org,2016:/users/jt_smith//242.7543#17112522016-06-14T17:47:00ZGraham Knop
Here's an example of a failure using the type of check you showed.

I don't think anyone's happy that smart match couldn't be fixed properly, but if you remove all of the cases that "suck", there's basically nothing left.]]>
Commented on Travis-CI and latest version of Perl 5 in Gábor Szabó - גאבור סבוtag:blogs.perl.org,2015:/users/gabor_szabo//272.7049#16158062015-09-17T21:47:55ZGraham Knop
Adding a 'latest stable' target to travis-perl helpers isn't something that had occurred to me, but if you think it would be worthwhile, I could definitely do so. And I would certainly welcome any other feedback on it too.]]>
Posted Moo 2.0 to Graham Knoptag:blogs.perl.org,2015:/users/graham_knop//248.66872015-02-05T17:08:14Z2015-02-05T17:08:36ZThe next stable release of Moo will be version 2.0, and will include some incompatible changes. These changes should affect a pretty small number of modules, and may help point out flaws in the existing code. The most important change...Graham Knophttp://blogs.perl.org/mt/mt-cp.fcgi?__mode=view&blog_id=248&id=437
The next stable release of Moo will be version 2.0, and will include some
incompatible changes. These changes should affect a pretty small number of
modules, and may help point out flaws in the existing code.

The most important change in Moo 2.0 is that it will no longer be applying
fatal warnings to classes using it. As Moo has grown to be more widely used on
CPAN, it has become obvious that applying fatal warnings is usually unexpected
or undesired by other authors, resulting in things like
Moo::Lax, or people just avoiding Moo
entirely. And authors who prefer fatal warnings can easily apply them to their
own code.

Moo 2.0 will also detect a number of cases where people apply modifiers to
constructors, or attempt to add attributes to classes that have already been
instantiated. These cases never worked correctly, but they will now issue
errors.

Another smaller change is that classes without attributes would previously
store all parameters to ->new in the object. This was a bug, but had backward
compatibility concerns.

I've done testing on all modules depending on Moo, and only found a small
number that these changes caused issues with. In most cases, it indicated a
bug in the module that hadn't been caught yet.

There is a beta version of Moo 2.0 available on CPAN now as Moo
1.999_001. If you have code
that depends on Moo, please test it with this new version.

]]>
Commented on Kiss Kiss Shebang Shebang in Buddy Burdentag:blogs.perl.org,2015:/users/buddy_burden//1118.6650#15164592015-01-13T23:35:08ZGraham Knop
local::lib no longer loads File::Spec. The footnote mentions this, but is also incorrect. File::Spec isn't used on Windows or Mac OS X. It's only used on VMS and Mac OS Classic, where it seems unlikely the rest of local::lib will work anyway.]]>
Posted Travis-CI Helpers for Perl to Graham Knoptag:blogs.perl.org,2014:/users/graham_knop//248.64492014-10-07T22:20:00Z2014-10-09T07:53:22ZI deal with a lot of modules that promise backwards compatibility with older versions of perl, usually back to perl 5.8.1. Since I don't regularly use perl versions that old when developing, accidentally introducing incompatibilities is always a risk. Having...Graham Knophttp://blogs.perl.org/mt/mt-cp.fcgi?__mode=view&blog_id=248&id=437
I deal with a lot of modules that promise backwards compatibility with older
versions of perl, usually back to perl 5.8.1. Since I don't regularly use perl
versions that old when developing, accidentally introducing incompatibilities is
always a risk. Having a continuous integration system check this for me makes
it much easier to catch mistakes like this before they get released into the
wild.

Travis CI is a very useful continuous integration
service that is free for any public repositories on
GitHub. There are issues with using Travis CI for the
kind of testing I need though. First, it only provides the last revision of
each perl series. Especially in the perl 5.8 and 5.10 series, there are
substantial enough differences between them that testing only the latest isn't
adequate. Additionally, some of the testing needs to be done on perls built
with threading, which isn't included on most of the versions available on
Travis. It also is sometimes useful to test without any additional modules
pre-installed like Travis does.

There is a solution for this though. Perl can be built directly on the Travis
test boxes before running the tests. Any arbitrary perl version can be built,
including blead (perl from git) or new stable releases that haven't been
included on Travis yet (like was the case with 5.20 for a few months).

Building new perl versions was what originally inspired me to begin work on my
Travis helper scripts. Since then, they have expanded to include a number of
other functions to simplify testing perl modules on Travis.

The Simple Version

The helpers can be used individually to customize the building and testing
process, but for most distributions the automatic mode will work. A
simple .travis.yml using my helper scripts would look like this:

While the automatic mode supports most of the features the helpers provide, it
isn't meant to be used with custom build steps. If any customization of the
build steps is needed, the automatic mode shouldn't be used.

Perl Building - build-perl

The first important helper function is build-perl. It takes the requested
perl version from the build matrix and either downloads or builds it for you if
it doesn't exist. So for example, if 5.16 is requested, Travis will
already have it available and nothing will be done. But if 5.16.0 is
requested, a fresh version of perl will be built. If 5.8.8 is requested,
a pre-built copy of perl 5.8.8 will be downloaded, as it's a commonly tested
version so I've pre-built it. Building perl generally takes around 4 minutes on
Travis, so these pre-built copies can significantly speed up small test suites.

Build flags can also be added to the versions. 5.8.5-thr will build a
version of perl including support for threads. 5.8.5-dbg will include
debugging support. And 5.16-thr will build the latest 5.16 release and
include support for threads.

If blead is requested, perl will be built from git. This is helpful to
see if your module will be impacted by future changes to perl, but as blead is
not guaranteed stable it should usually be included in Travis's
allow_failures
section.

Pre-installed Modules - local-lib

When the helper scripts build or download a perl version, they don't have any
extra modules pre-installed. The default Travis builds all include a set of
prerequisites pre-installed. Both cases can be useful for different situations.
In some cases, you want to that your prerequisite installation works properly,
or that your module works with an older version of a core module. But
installing all of the prerequisites every time can delay testing by a
significant amount.

To help with this, each pre-built copy of perl also has a set of pre-built
local::lib directories that can be switched to. These can be used by adding
them directly to the build matrix, attaching them to the perl version like
5.10.1@moose. The moose pre-built includes Moose and Moo. If not
using a pre-built perl, the modules in the named local::lib will be installed.

The full list of pre-built local::libs and the libraries in them can be seen in
the
local-libs.txt
file.

Distribution Building - build-dist

There are a variety of tools used for distribution building. Manually writing a
Makefile.PL is one, but other options include Module::Build, Module::Install, or
Dist::Zilla. While tests can often be performed directly against the files in
the repository without building, this won't include any of the extra checks done
by or generated by the dist building tool. It also can complicate the process
of finding prerequisites.

The approach the helpers recommend is first generating a full dist like would be
uploaded to CPAN, then testing against that. Because the distribution building
tool often won't work on all of the perl versions you wish to test against, it's
helpful to use a different (newer) version of perl than the tests are run with.

This is what the build-dist helper does. It uses the latest pre-built
version of perl to generate a distribution directory, automatically installing
any modules needed. It then sets the BUILD_DIR environment variable to
the location of the built distribution.

Prerequisite Installation - cpan-install

For most cases, prerequisite installation could be handled by cpanm, but
the cpan-install helper provides a few niceties. It provides more helpful
output than cpanm in the event of a failure, but is still concise in the common
case. It also tweaks the set of modules to be installed. The developer
prerequisites and recommended modules of the distribution being tested will be
installed, but not those of its prerequisites.

It also includes better compatibility with ancient versions of perl.

Coverage Reporting

Setting up coverage reporting in Travis is relatively simple. You just need to
install the Devel::Cover module and run the cover command appropriately. But
coverage reporting slows down testing substantially and can also prevent some
tests from running (such as those using threads). So it's useful to limit
coverage testing to only some of the perls you are testing with. With that in
mind, the helper scripts include several coverage related commands that are
no-ops unless the COVERAGE environment variable is set.

Running the Tests

For running the actual tests, the helpers do very little. It's recommended to
use the standard prove command, with whatever options are wanted.

There are a few helpers that can be used with prove though. If you want to run
tests in parallel, the test-jobs returns a recommended number of
processes to use. The number is one more than the number CPUs available. It
also will always return 1 if COVERAGE is enabled, since Devel::Cover is
currently buggy when used with parallel testing.

The test-files returns all of the test scripts to run. This is generated
by searching for .t files recursively in the t and xt
directories. However, if the AUTHOR_TESTING environment variable is set to 0,
it will only return files in t. It can also help with very slow test
runs. If the TEST_PARTITION and `TEST_PARTITIONS environment variables are set,
it will return only a subset of the tests. This allows you to split the tests
across multiple Travis builds in parallel, making the full test run take less
time.

Bits and Pieces

An important feature of the helpers is that they can all be used independently
of each other. So if perl building is the only feature needed, the rest of the
helpers can be ignored.

Overall, having these helpers has allowed me to set up testing easier for a
variety of different projects, and allowed me to expand the versions of perl
tests. They have been used to add perl 5.8 and blead testing to Moose, and perl 5.6
testing to Moo and ExtUtils::MakeMaker.

]]>
Commented on perlbrew on OSX in Chiseltag:blogs.perl.org,2014:/users/chisel//409.6248#14133622014-07-31T14:53:46ZGraham Knop
The problem is that you are installing modules into a local::lib, but that directory isn't part of the library search path. PERL_CPANM_OPT=--local-lib ~/perl5 means that things are always installed into ~/perl5, but the corresponding PERL5LIB isn't set up to load from there. With perlbrew, you can either install modules directly into perl's normal paths by dropping the local::lib entirely, or you can use perlbrew's built in local::lib support.

perlbrew lib create base; perlbrew switch perl-5.20.0@base

]]>
Commented on perlbrew on OSX in Chiseltag:blogs.perl.org,2014:/users/chisel//409.6248#14133272014-07-31T09:58:58ZGraham Knop
The output of cpanm -v MP3::Info would be very helpful in tracking down the problem.]]>
Commented on How to Run a Single Test via Dist::Zilla in Olaf Alderstag:blogs.perl.org,2014:/users/olaf_alders//280.6170#14114342014-06-30T18:39:42ZGraham Knop
If you are dealing with XS code, you'll need prove's -b option instead of -l]]>
Commented on Conflict Resolution: local::lib and git's Perl in preactiontag:blogs.perl.org,2014:/users/preaction//398.6128#14042512014-06-16T01:00:03ZGraham Knop
I have a pending addition to local::lib that will install perl modules in a version specific directory. perl will then automatically pick those directories up, even they won't be listed directly in PERL5LIB.

This will mostly fix problems of this sort.

]]>
Commented on Moose, Mouse, Moo what next 'M' in byterocktag:blogs.perl.org,2014:/users/byterock//2165.5806#13357962014-03-20T12:50:49ZGraham Knop
There's no reason OO is less appropriate for CGI or command line programs, especially if they share components with a larger system.

The only real concern is if the overhead is worth it. And for Moo and Mouse, you won't even notice their load time. The accessors they create will be as fast as or faster than anything you write yourself.

Moo also gives you get the benefit of being able to cleanly inter-operate with a larger system. So if you have something like a Catalyst driven web site, it can share components with utility scripts, and they can still be fast.

]]>
Commented on Extracting values from a list of (key, value) pairs in Diab Jeriustag:blogs.perl.org,2014:/users/diab_jerius//956.5750#13290152014-03-07T06:40:59ZGraham Knop
There is a small mistake in your code. @N has an odd number of elements. pairkeys will warn about this if warnings are on.