Skip to content

Commit

Permalink
CPAN Release 0.24
Browse files Browse the repository at this point in the history
- Change to API version v2
  • Loading branch information
ingydotnet committed Dec 18, 2014
1 parent 7ffb544 commit 17c85ec
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 96 deletions.
5 changes: 5 additions & 0 deletions Changes
@@ -1,4 +1,9 @@
---
version: 0.24
date: Wed Dec 17 17:52:05 PST 2014
changes:
- Change to API version v2
---
version: 0.23
date: Tue Dec 16 23:58:49 EST 2014
changes:
Expand Down
2 changes: 1 addition & 1 deletion Meta
@@ -1,7 +1,7 @@
=meta: 0.0.1

name: Inline-Module
version: 0.23
version: 0.24
abstract: Support for Inline-based CPAN Extension Modules
homepage: https://metacpan.org/release/Inline-Module

Expand Down
24 changes: 7 additions & 17 deletions doc/Inline/Module/Tutorial.swim
Expand Up @@ -73,7 +73,7 @@ Normally you use [Inline::C] like this:
but here we just change `Inline` to `Acme::Math::XS::Inline`. This is the key
part of how Inline::Module works. Since we want to /use/ Inline but not
/depend/ on it when the user installs this module, we do this trick. The
`::Inline` module is a little generated stub that knows how to do all the
`::Inline` module is a little generated *stub* that knows how to do all the
right magics.

== The Inline Stub Module
Expand All @@ -86,13 +86,12 @@ You'll get a `lib/Acme/Math/XS/Inline.pm` that looks like this:

use strict; use warnings;
package Acme::Math::XS::Inline;
use Inline::Module 'v1' => '1.23';
use Inline::Module stub => 'v2';
1;

The astute tutorialist will note that this module depends on `Inline` and
`Inline::Module`, and that's a no-no. That's because this stub is used for
author side development and testing, and another stub replaces it at module
release time.
The astute tutorialist will note that this module depends on `Inline::Module`,
and that's a no-no. That's because this stub is used for author side
development and testing, and another stub replaces it at module release time.

That stub will look like this:

Expand All @@ -118,15 +117,7 @@ as in-memory files. For instance if you just run your tests with:

prove -l t/

the stub modules will be autogenerated. If you'd rather see the stubs be
generated as real files under the `lib` or `blib` directory, use one of these:

export PERL5OPT='-MInline::Module=autostub,lib,Acme::Math::XS::Inline'
export PERL5OPT='-MInline::Module=autostub,blib,Acme::Math::XS::Inline'

Then you'll need to add the `-b` flag for `blib` testing:

prove -lb t/
the stub modules will be autogenerated, just-in-time, in memory.

== Testing

Expand Down Expand Up @@ -183,10 +174,9 @@ In the `distdir` phase, we need to:

* Add the `Inline` modules that control building, under `inc/`:
* Inline::Module
* Inline::Module::Makemaker
* Inline
* Inline::C
* a couple helper modules
* a few more helper modules

We also need to move the test/build `lib/Acme/Math/XS/Inline.pm` under `inc/`
and put the `Dynaloader` version in its place under `lib`.
Expand Down
77 changes: 29 additions & 48 deletions lib/Inline/Module.pm
@@ -1,6 +1,7 @@
use strict; use warnings;
package Inline::Module;
our $VERSION = '0.23';
our $VERSION = '0.24';
our $API_VERSION = 'v2';

use Config();
use File::Path();
Expand Down Expand Up @@ -41,32 +42,27 @@ sub import {
return unless @_;
my $cmd = shift;

return $class->handle_makestub(@_)
if $cmd eq 'makestub';
return $class->handle_stub($stub_module, @_)
if $cmd eq 'stub';
return $class->handle_autostub(@_)
if $cmd eq 'autostub';
return $class->handle_distdir(@ARGV)
if $cmd eq 'distdir';
return $class->handle_fixblib()
if $cmd eq 'fixblib';

if ($cmd =~ /^v[0-9]$/) {
$class->check_api_version($stub_module, $cmd => @_);
no strict 'refs';
*{"${stub_module}::import"} = $class->importer($stub_module);
return;
}
return $class->handle_makestub(@_)
if $cmd eq 'makestub';

die "Unknown Inline::Module::import argument '$cmd'"
}

sub check_api_version {
my ($class, $stub_module, $api_version, $inline_module_version) = @_;
if ($api_version ne 'v1' or $inline_module_version ne $VERSION) {
my ($class, $stub_module, $api_version) = @_;
if ($api_version ne $API_VERSION) {
warn <<"...";
It seems that '$stub_module' is out of date.
It is using Inline::Module version '$inline_module_version'.
You have Inline::Module version '$VERSION' installed.
It is using Inline::Module API version '$api_version'.
You have Inline::Module API version '$API_VERSION' installed.
Make sure you have the latest version of Inline::Module installed, then run:
Expand Down Expand Up @@ -177,26 +173,27 @@ sub included_modules {
#------------------------------------------------------------------------------
# Class methods.
#------------------------------------------------------------------------------
sub handle_stub {
my ($class, $stub_module, $api_version) = @_;
$class->check_api_version($stub_module, $api_version);
no strict 'refs';
*{"${stub_module}::import"} = $class->importer($stub_module);
return;
}

sub handle_makestub {
my ($class, @args) = @_;

my $dest;
my @modules;
for my $arg (@args) {
if ($arg eq 'blib') {
$dest = 'blib/lib';
}
elsif ($arg =~ m!/!) {
$dest = $arg;
}
elsif ($arg =~ /::/) {
if ($arg =~ /::/) {
push @modules, $arg;
}
else {
croak "Unknown 'makestub' argument: '$arg'";
}
}
$dest ||= 'lib';
my $dest = 'lib';

for my $module (@modules) {
my $code = $class->proxy_module($module);
Expand All @@ -222,45 +219,26 @@ sub handle_autostub {
require lib;
lib->import('lib');

my ($dest, %autostub_modules);
my %autostub_modules;
for my $arg (@args) {
if ($arg =~ m!::!) {
$autostub_modules{$arg} = 1;
}
elsif ($arg =~ m!(^(b?lib$|mem)$|/)!) {
croak "Invalid arg '$arg'. Dest path already set to '$dest'"
if $dest;
$dest = $arg eq 'blib' ? 'blib/lib' : $arg;
}
else {
croak "Unknown 'autostub' argument: '$arg'";
}
}
$dest ||= 'mem';

push @INC, sub {
my ($self, $module_path) = @_;
my ($self, $module) = @_;
delete $ENV{PERL5OPT};

my $module = $module_path;
$module =~ s!\.pm$!!;
$module =~ s!/!::!g;
$autostub_modules{$module} or return;

if ($dest eq 'mem') {
my $code = $class->proxy_module($module);
open my $fh, '<', \$code;
return $fh;
}

my $path = "$dest/$module_path";
if (not -e $path) {
my $code = $class->proxy_module($module);
$class->write_module($dest, $module, $code);
print "Created stub module '$path' (Inline::Module $VERSION)\n";
}

open my $fh, '<', $path or die "Can't open '$path' for input:\n$!";
my $code = $class->proxy_module($module);
open my $fh, '<', \$code;
return $fh;
}
}
Expand Down Expand Up @@ -342,11 +320,14 @@ sub proxy_module {
# This module is for author-side development only. When this module is shipped
# to CPAN, it will be automagically replaced with content that does not
# require any Inline framework modules (or any other non-core modules).
#
# To regenerate this stub module, run this command:
#
# perl -MInline::Module=makestub,$module
use strict; use warnings;
package $module;
use Inline::Module 'v1' => '$VERSION';
use Inline::Module stub => '$API_VERSION';
1;
...
}
Expand Down
24 changes: 0 additions & 24 deletions test/devel/generate-stub.t
Expand Up @@ -19,30 +19,6 @@ BAIL_ON_FAIL
# ok "`[ ! -e lib ] && [ ! -e blib ]`" "Neither lib nor blib exist"
}

{
(
export PERL5OPT=-MInline::Module=autostub,lib,Foo::Bar
perl -e 'use Foo::Bar'
)
ok "`[ -f lib/Foo/Bar.pm ]`" "Stub file auto-generated into lib"
rm -fr lib
}

{
perl -MInline::Module=makestub,Foo::Bar,blib
ok "`[ -f blib/lib/Foo/Bar.pm ]`" "Stub file generated into blib"
rm -fr blib
}

{
(
export PERL5OPT=-MInline::Module=autostub,Foo::Bar,blib
perl -e 'use Foo::Bar'
)
ok "`[ -f blib/lib/Foo/Bar.pm ]`" "Stub file auto-generated into blib"
rm -fr blib
}

done_testing
teardown

Expand Down
6 changes: 0 additions & 6 deletions test/devel/test-acme-math-xs.t
Expand Up @@ -7,12 +7,6 @@ BAIL_ON_FAIL
git clone $TEST_HOME/../acme-math-xs-pm/.git -b eumm
cd acme-math-xs-pm

{
perl -MInline::Module=autostub,lib,Acme::Math::XS::Inline \
-MAcme::Math::XS::Inline -e1
ok "`[ -f lib/Acme/Math/XS/Inline.pm ]`" "The stub file exists"
}

{
prove -lv t &> out
pass "Acme::Math::XS passes its tests"
Expand Down

0 comments on commit 17c85ec

Please sign in to comment.