<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Imager::ExtUtils;
use strict;

use vars qw($VERSION);

$VERSION = "1.000";

=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 =&gt; '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&lt;with&gt; hook.

=cut

sub inline_config {
  my ($class) = @_;
  my $base = base_dir();

  return
    {
     INC =&gt; $class-&gt;includes,
     TYPEMAPS =&gt; $class-&gt;typemap,
     AUTO_INCLUDE =&gt; &lt;&lt;'CODE',
#include "imext.h"
#include "imperl.h"
DEFINE_IMAGER_CALLBACKS;
CODE
     BOOT =&gt; 'PERL_INITIALIZE_IMAGER_CALLBACKS;',
     FILTERS =&gt; \&amp;_inline_filter,
    };
}

my @inline_replace =
  qw(
   Imager::ImgRaw
   Imager::Color::Float
   Imager::Color
   Imager::IO
  );

my %inline_replace =
  map { (my $tmp = $_) =~ s/::/__/g; $_ =&gt; $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-&gt;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-&gt;base_dir();

  $base . '/Imager/typemap';
}

1;

__END__

=back

=head1 AUTHOR

Tony Cook &lt;tony@imager.perl.org&gt;

=head1 REVISION

$Revision$

=head1 SEE ALSO

Imager, Imager::API, Imager::Inline, Imager::APIRef.

=cut
</pre></body></html>