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