Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 476e1788c045c6f1fcde651c18cd8793a07c7c02 @jberger jberger committed Dec 27, 2011
Showing with 87 additions and 0 deletions.
  1. +20 −0 Build.PL
  2. +4 −0 MANIFEST
  3. +3 −0 README
  4. +32 −0 lib/Alien/Base.pm
  5. +28 −0 t/version.t
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+
+use Module::Build;
+
+my $builder = Module::Build->new(
+ module_name => 'Alien::Base',
+ dist_abstract => 'A base class for Alien:: modules',
+ license => 'perl',
+ dist_author => 'Joel A. Berger <joel.a.berger@gmail.com>',
+ license => 'perl',
+ requires => {
+ 'perl' => '5.8.1',
+ 'parent' => 0,
+ 'Capture::Tiny' => 0,
+ #'Sort::Versions' => 0,
+ },
+);
+
+$builder->create_build_script;
@@ -0,0 +1,4 @@
+Build.PL
+lib/Alien/Base.pm
+MANIFEST This list of files
+t/version.t
3 README
@@ -0,0 +1,3 @@
+Alien::Base will be a base class to help build Alien:: modules for simple libraries.
+
+Initially the target will be Alien::GSL (and probably other Gnu libraries) but in principle there is no limitation.
@@ -0,0 +1,32 @@
+package Alien::Base;
+
+use parent 'Module::Build';
+
+use Capture::Tiny 'capture_stderr';
+
+our $VERSION = 0.01;
+$VERSION = eval $VERSION;
+
+our $Verbose ||= 0;
+
+## Extra parameters in $self (all should start with 'alien_')
+# alien_name -- name of library
+# alien_version_check -- command to execute to check if install/version
+
+sub alien_check_installed_version {
+ my $self = shift;
+ my $name = $self->{alien_name};
+ my $command = $self->{alien_version_check} || "pkg-config --modversion $name";
+
+ my $version;
+ my $err = capture_stderr {
+ $version = `$command` || 0;
+ };
+
+ print "Command `$command` had stderr: $err" if ($Verbose and $err);
+
+ return $version;
+}
+
+1;
+
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+use Test::More;
+use_ok('Alien::Base');
+
+my $skip;
+system( 'pkg-config --version' );
+if ( $? ) {
+ $skip = "Cannot use pkg-config: $?";
+}
+
+SKIP: {
+ skip $skip, 2 if $skip;
+
+ my @installed = map { /^(\S+)/ ? $1 : () } `pkg-config --list-all`;
+ my $lib = $installed[0];
+
+ my $builder_ok = bless { alien_name => $lib }, 'Alien::Base';
+ my $builder_bad = bless { alien_name => 'siughspidghsp' }, 'Alien::Base';
+
+ is( !! $builder_ok->alien_check_installed_version, 1, "Found installed library $lib" );
+ is( $builder_bad->alien_check_installed_version, 0, 'Returns 0 if not found' );
+
+}
+
+done_testing;
+

0 comments on commit 476e178

Please sign in to comment.