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