Dist-Zilla-Plugin-XSVersion
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/XSVersion.pm view on Meta::CPAN
package Dist::Zilla::Plugin::XSVersion;
# ABSTRACT: a thing
$Dist::Zilla::Plugin::XSVersion::VERSION = '0.01';
use strict;
use warnings;
use Moose;
with 'Dist::Zilla::Role::FileMunger';
sub munge_file {
my ($self, $file) = @_;
return unless $file->name =~ /\.pm$/;
my $perl = $file->content;
my ($line, $module) = $perl =~ /((\$[\w:]+?::)VERSION.+?;)/;
$perl =~ s/((\$[\w:]+?::)VERSION.+?;)/$2XS_VERSION = $1/;
$perl =~ s/XSLoader::load\(([^)]+)\)/XSLoader::load($1, ${module}XS_VERSION)/;
$file->content($perl);
}
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Dist::Zilla::Plugin::XSVersion - a thing
=head1 VERSION
version 0.01
=head1 SYNOPSIS
# dist.ini
[XSVersion]
# MyModule.pm
package MyModule;
require XSLoader;
XSLoader::load('MyModule');
=head1 DESCRIPTION
A hackey, quick plugin to implement the commonly used $XS_VERSION pattern
required in order to support XS-loading of trial releases. This is not
possible using L<Dist::Zilla::Plugin::PkgVersion>, which will generate
something like:
$MyModule::VERSION = '0.123_1'; # first line for CPAN indexer
$MyModule::VERSION = '0.1231'; # next line for internal versioning
Without an explicit second argument, L<XSLoader/load> will attempt to load the
compiled module using a C<VERSIONCHECK> against the value of
C<$MyModule::VERSION>, which no longer matches C<0.123_1> after being
overwritten.
$MyModule::VERSION = '0.123_1'; # first line for CPAN indexer
$MyModule::VERSION = '0.1231'; # next line for internal versioning
XSLoader::load('MyModule'); # gets the wrong $VERSION
This plugin rewrites the code above to something like:
$MyModule::XS_VERSION = $MyModule::VERSION = '0.123_1';
$MyModule::VERSION = '0.1231';
XSLoader::load('MyModule', $MyModule::XS_VERSION);
=head1 CAVEATS
( run in 1.062 second using v1.01-cache-2.11-cpan-5b529ec07f3 )