- write out the image size in bytes field of a BMP correctly.
[imager.git] / lib / Imager / ExtUtils.pm
CommitLineData
92bda632
TC
1package Imager::ExtUtils;
2use strict;
3
2a445fb8
TC
4use vars qw($VERSION);
5
22f9ca48 6$VERSION = "1.001";
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 {
30 for my $dir (@INC) {
31 if (-e "$dir/Imager.pm") {
32 return $dir;
33 }
34 }
35
36 die "Cannot locate an installed Imager!";
37}
38
39=item inline_config
40
41Implements Imager's Inline::C C<with> hook.
42
43=cut
44
45sub inline_config {
46 my ($class) = @_;
47 my $base = base_dir();
48
49 return
50 {
51 INC => $class->includes,
52 TYPEMAPS => $class->typemap,
22f9ca48
TC
53 AUTO_INCLUDE => <<CODE,
54/* Inserted by Imager $Imager::VERSION */
92bda632
TC
55#include "imext.h"
56#include "imperl.h"
57DEFINE_IMAGER_CALLBACKS;
58CODE
59 BOOT => 'PERL_INITIALIZE_IMAGER_CALLBACKS;',
60 FILTERS => \&_inline_filter,
61 };
62}
63
64my @inline_replace =
65 qw(
66 Imager::ImgRaw
67 Imager::Color::Float
68 Imager::Color
69 Imager::IO
70 );
71
72my %inline_replace =
73 map { (my $tmp = $_) =~ s/::/__/g; $_ => $tmp } @inline_replace;
74
75my $inline_replace_re = "\\b(" . join('|', @inline_replace) . ")\\b";
76
77sub _inline_filter {
78 my $code = shift;
79
80 $code =~ s/$inline_replace_re/$inline_replace{$1}/g;
81
82 $code;
83}
84
85=item includes
86
87Returns -I options suitable for use with ExtUtils::MakeMaker's INC
88option.
89
90=cut
91
92sub includes {
93 my $class = shift;
94 my $base = $class->base_dir();
95
96 "-I" . $base . '/Imager/include',
97}
98
99=item typemap
100
101Returns the full path to Imager's installed typemap.
102
103=cut
104
105sub typemap {
106 my $class = shift;
107 my $base = $class->base_dir();
108
109 $base . '/Imager/typemap';
110}
111
1121;
113
114__END__
115
116=back
117
118=head1 AUTHOR
119
120Tony Cook <tony@imager.perl.org>
121
122=head1 REVISION
123
124$Revision$
125
126=head1 SEE ALSO
127
128Imager, Imager::API, Imager::Inline, Imager::APIRef.
129
130=cut