| 1 | package Imager::ExtUtils; | ||||||||||
| 2 | 3 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | our $VERSION = "1.004"; | |||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Imager::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 | |||||||||||
| 24 | Returns the base directory where Imager is installed. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | # figure out where Imager is installed | ||||||||||
| 29 | 3 | ▶ | sub base_dir { | ||||||||
|
Subroutine
base_dir: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 30 | 3 | for my $inc_dir (@INC) { | |||||||||
| 31 | 6 | ▶ | if (-e "$inc_dir/Imager.pm") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 3 | my $base_dir = $inc_dir; | |||||||||
| 33 | 3 | ▶ | unless (File::Spec->file_name_is_absolute($base_dir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 1 | $base_dir = File::Spec->rel2abs($base_dir); | |||||||||
| 35 | } | ||||||||||
| 36 | 3 | return $base_dir; | |||||||||
| 37 | } | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | die "Cannot locate an installed Imager!"; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | =item inline_config | ||||||||||
| 44 | |||||||||||
| 45 | Implements Imager's Inline::C C<with> hook. | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub inline_config { | ||||||||
|
Subroutine
inline_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 50 | 0 | my ($class) = @_; | |||||||||
| 51 | 0 | my $base = base_dir(); | |||||||||
| 52 | |||||||||||
| 53 | return | ||||||||||
| 54 | { | ||||||||||
| 55 | 0 | INC => $class->includes, | |||||||||
| 56 | TYPEMAPS => $class->typemap, | ||||||||||
| 57 | AUTO_INCLUDE => <<CODE, | ||||||||||
| 58 | /* Inserted by Imager $Imager::VERSION */ | ||||||||||
| 59 | #include "imext.h" | ||||||||||
| 60 | #include "imperl.h" | ||||||||||
| 61 | DEFINE_IMAGER_CALLBACKS; | ||||||||||
| 62 | CODE | ||||||||||
| 63 | BOOT => 'PERL_INITIALIZE_IMAGER_CALLBACKS;', | ||||||||||
| 64 | FILTERS => \&_inline_filter, | ||||||||||
| 65 | }; | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 3 | my @inline_replace = | |||||||||
| 69 | qw( | ||||||||||
| 70 | Imager::ImgRaw | ||||||||||
| 71 | Imager::Color::Float | ||||||||||
| 72 | Imager::Color | ||||||||||
| 73 | Imager::IO | ||||||||||
| 74 | ); | ||||||||||
| 75 | |||||||||||
| 76 | my %inline_replace = | ||||||||||
| 77 | 3 | map { (my $tmp = $_) =~ s/::/__/g; $_ => $tmp } @inline_replace; | |||||||||
| 78 | |||||||||||
| 79 | 3 | my $inline_replace_re = "\\b(" . join('|', @inline_replace) . ")\\b"; | |||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | sub _inline_filter { | ||||||||
|
Subroutine
_inline_filter: not called CC=1 SCAR=6.9
| |||||||||||
| 82 | 0 | my $code = shift; | |||||||||
| 83 | |||||||||||
| 84 | 0 | $code =~ s/$inline_replace_re/$inline_replace{$1}/g; | |||||||||
| 85 | |||||||||||
| 86 | 0 | $code; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | =item includes | ||||||||||
| 90 | |||||||||||
| 91 | Returns -I options suitable for use with ExtUtils::MakeMaker's INC | ||||||||||
| 92 | option. | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 1 | ▶ | sub includes { | ||||||||
|
Subroutine
includes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 97 | 1 | my $class = shift; | |||||||||
| 98 | 1 | my $base = $class->base_dir(); | |||||||||
| 99 | |||||||||||
| 100 | 1 | "-I" . $base . '/Imager/include', | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | =item typemap | ||||||||||
| 104 | |||||||||||
| 105 | Returns the full path to Imager's installed typemap. | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||
| 108 | |||||||||||
| 109 | 1 | ▶ | sub typemap { | ||||||||
|
Subroutine
typemap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 110 | 1 | my $class = shift; | |||||||||
| 111 | 1 | my $base = $class->base_dir(); | |||||||||
| 112 | |||||||||||
| 113 | 1 | $base . '/Imager/typemap'; | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 3 | 1; | |||||||||
| 117 | |||||||||||
| 118 | __END__ | ||||||||||