]> git.imager.perl.org - imager.git/blame - lib/Imager/ExtUtils.pm
eliminate use vars
[imager.git] / lib / Imager / ExtUtils.pm
CommitLineData
92bda632 1package Imager::ExtUtils;
ee64a81f 2use 5.006;
92bda632 3use strict;
c586eb58 4use File::Spec;
92bda632 5
ee64a81f 6our $VERSION = "1.003";
2a445fb8 7
92bda632
TC
8=head1 NAME
9
10Imager::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
24Returns the base directory where Imager is installed.
25
26=cut
27
28# figure out where Imager is installed
29sub base_dir {
c586eb58
TC
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;
92bda632
TC
37 }
38 }
39
40 die "Cannot locate an installed Imager!";
41}
42
43=item inline_config
44
45Implements Imager's Inline::C C<with> hook.
46
47=cut
48
49sub inline_config {
50 my ($class) = @_;
51 my $base = base_dir();
52
53 return
54 {
55 INC => $class->includes,
56 TYPEMAPS => $class->typemap,
22f9ca48
TC
57 AUTO_INCLUDE => <<CODE,
58/* Inserted by Imager $Imager::VERSION */
92bda632
TC
59#include "imext.h"
60#include "imperl.h"
61DEFINE_IMAGER_CALLBACKS;
62CODE
63 BOOT => 'PERL_INITIALIZE_IMAGER_CALLBACKS;',
64 FILTERS => \&_inline_filter,
65 };
66}
67
68my @inline_replace =
69 qw(
70 Imager::ImgRaw
71 Imager::Color::Float
72 Imager::Color
73 Imager::IO
74 );
75
76my %inline_replace =
77 map { (my $tmp = $_) =~ s/::/__/g; $_ => $tmp } @inline_replace;
78
79my $inline_replace_re = "\\b(" . join('|', @inline_replace) . ")\\b";
80
81sub _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
91Returns -I options suitable for use with ExtUtils::MakeMaker's INC
92option.
93
94=cut
95
96sub includes {
97 my $class = shift;
98 my $base = $class->base_dir();
99
100 "-I" . $base . '/Imager/include',
101}
102
103=item typemap
104
105Returns the full path to Imager's installed typemap.
106
107=cut
108
109sub typemap {
110 my $class = shift;
111 my $base = $class->base_dir();
112
113 $base . '/Imager/typemap';
114}
115
1161;
117
118__END__
119
120=back
121
122=head1 AUTHOR
123
5b480b14 124Tony Cook <tonyc@cpan.org>
92bda632
TC
125
126=head1 REVISION
127
128$Revision$
129
130=head1 SEE ALSO
131
132Imager, Imager::API, Imager::Inline, Imager::APIRef.
133
134=cut