| 1 |
package Imager::ExtUtils; |
| 2 |
use 5.006; |
| 3 |
use strict; |
| 4 |
use File::Spec; |
| 5 |
|
| 6 |
our $VERSION = "1.003"; |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Imager::ExtUtils - functions handy in writing Imager extensions |
| 11 |
|
| 12 |
=head1 SYNOPSIS |
| 13 |
|
| 14 |
# make Imager easier to use with Inline |
| 15 |
# perldoc Imager::Inline |
| 16 |
use Inline with => 'Imager'; |
| 17 |
|
| 18 |
=head1 DESCRIPTION |
| 19 |
|
| 20 |
=over |
| 21 |
|
| 22 |
=item base_dir |
| 23 |
|
| 24 |
Returns the base directory where Imager is installed. |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
# figure out where Imager is installed |
| 29 |
sub base_dir { |
| 30 |
for my $inc_dir (@INC) { |
| 31 |
if (-e "$inc_dir/Imager.pm") { |
| 32 |
my $base_dir = $inc_dir; |
| 33 |
unless (File::Spec->file_name_is_absolute($base_dir)) { |
| 34 |
$base_dir = File::Spec->rel2abs($base_dir); |
| 35 |
} |
| 36 |
return $base_dir; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
die "Cannot locate an installed Imager!"; |
| 41 |
} |
| 42 |
|
| 43 |
=item inline_config |
| 44 |
|
| 45 |
Implements Imager's Inline::C C<with> hook. |
| 46 |
|
| 47 |
=cut |
| 48 |
|
| 49 |
sub inline_config { |
| 50 |
my ($class) = @_; |
| 51 |
my $base = base_dir(); |
| 52 |
|
| 53 |
return |
| 54 |
{ |
| 55 |
INC => $class->includes, |
| 56 |
TYPEMAPS => $class->typemap, |
| 57 |
AUTO_INCLUDE => <<CODE, |
| 58 |
/* Inserted by Imager $Imager::VERSION */ |
| 59 |
#include "imext.h" |
| 60 |
#include "imperl.h" |
| 61 |
DEFINE_IMAGER_CALLBACKS; |
| 62 |
CODE |
| 63 |
BOOT => 'PERL_INITIALIZE_IMAGER_CALLBACKS;', |
| 64 |
FILTERS => \&_inline_filter, |
| 65 |
}; |
| 66 |
} |
| 67 |
|
| 68 |
my @inline_replace = |
| 69 |
qw( |
| 70 |
Imager::ImgRaw |
| 71 |
Imager::Color::Float |
| 72 |
Imager::Color |
| 73 |
Imager::IO |
| 74 |
); |
| 75 |
|
| 76 |
my %inline_replace = |
| 77 |
map { (my $tmp = $_) =~ s/::/__/g; $_ => $tmp } @inline_replace; |
| 78 |
|
| 79 |
my $inline_replace_re = "\\b(" . join('|', @inline_replace) . ")\\b"; |
| 80 |
|
| 81 |
sub _inline_filter { |
| 82 |
my $code = shift; |
| 83 |
|
| 84 |
$code =~ s/$inline_replace_re/$inline_replace{$1}/g; |
| 85 |
|
| 86 |
$code; |
| 87 |
} |
| 88 |
|
| 89 |
=item includes |
| 90 |
|
| 91 |
Returns -I options suitable for use with ExtUtils::MakeMaker's INC |
| 92 |
option. |
| 93 |
|
| 94 |
=cut |
| 95 |
|
| 96 |
sub includes { |
| 97 |
my $class = shift; |
| 98 |
my $base = $class->base_dir(); |
| 99 |
|
| 100 |
"-I" . $base . '/Imager/include', |
| 101 |
} |
| 102 |
|
| 103 |
=item typemap |
| 104 |
|
| 105 |
Returns the full path to Imager's installed typemap. |
| 106 |
|
| 107 |
=cut |
| 108 |
|
| 109 |
sub typemap { |
| 110 |
my $class = shift; |
| 111 |
my $base = $class->base_dir(); |
| 112 |
|
| 113 |
$base . '/Imager/typemap'; |
| 114 |
} |
| 115 |
|
| 116 |
1; |
| 117 |
|
| 118 |
__END__ |
| 119 |
|
| 120 |
=back |
| 121 |
|
| 122 |
=head1 AUTHOR |
| 123 |
|
| 124 |
Tony Cook <[email protected]> |
| 125 |
|
| 126 |
=head1 REVISION |
| 127 |
|
| 128 |
$Revision$ |
| 129 |
|
| 130 |
=head1 SEE ALSO |
| 131 |
|
| 132 |
Imager, Imager::API, Imager::Inline, Imager::APIRef. |
| 133 |
|
| 134 |
=cut |