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