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

require Exporter;

@ISA=(Exporter);
@EXPORT = ();

my $gtk;

sub _check_gtk {
   unless (defined $gtk) {
      eval { require Gtk }; $gtk = $@ eq "" &amp;&amp; $Gtk::VERSION&gt;=0.5;
   }
   $gtk;

}

my %description = (
   'gtk'        =&gt; 'the gtk perl module',
   'gtk-1.1'    =&gt; 'gtk+ version 1.1 or higher',
   'gtk-1.2'    =&gt; 'gtk+ version 1.2 or higher',
   'gtk-1.3'    =&gt; 'gtk+ version 1.3 or higher',
   'gtk-1.4'    =&gt; 'gtk+ version 1.4 or higher',

   'gimp-1.1'   =&gt; 'gimp version 1.1 or higher',
   'gimp-1.2'   =&gt; 'gimp version 1.2 or higher',
   'gimp-1.3'   =&gt; 'gimp version 1.3 or higher',

   'perl-5.005' =&gt; 'perl version 5.005 or higher',
   'pdl'        =&gt; 'compiled-in PDL support',
   'gnome'      =&gt; 'the gnome perl module',
   'gtkxmhtml'  =&gt; 'the Gtk::XmHTML module',
   'dumper'     =&gt; 'the Data::Dumper module',
   'never'      =&gt; '(for testing, will never be present)',
   'unix'	=&gt; 'a unix-like operating system',
   'persistency'=&gt; 'Gimp::Data can handle persistency',
);

sub import {
   my $pkg = shift;
   my $feature;

   local $Gimp::in_query=(@ARGV and $ARGV[0] eq "-gimp");
   while(defined (my $feature = shift)) {
      $feature=~s/^://;
      need($feature);
   }
}

sub describe {
   $description{$_[0]};
}

sub Gimp::Feature::list {
   keys %description;
}

sub present {
   local $_ = shift;

   if ($_ eq "gtk") {
      _check_gtk;
   } elsif ($_ eq "gtk-1.1") {
      _check_gtk and (Gtk-&gt;major_version==1 &amp;&amp; Gtk-&gt;minor_version&gt;=1) || Gtk-&gt;major_version&gt;1;
   } elsif ($_ eq "gtk-1.2") {
      _check_gtk and (Gtk-&gt;major_version==1 &amp;&amp; Gtk-&gt;minor_version&gt;=2) || Gtk-&gt;major_version&gt;1;
   } elsif ($_ eq "gtk-1.3") {
      _check_gtk and (Gtk-&gt;major_version==1 &amp;&amp; Gtk-&gt;minor_version&gt;=3) || Gtk-&gt;major_version&gt;1;
   } elsif ($_ eq "gtk-1.4") {
      _check_gtk and (Gtk-&gt;major_version==1 &amp;&amp; Gtk-&gt;minor_version&gt;=4) || Gtk-&gt;major_version&gt;1;

   } elsif ($_ eq "gimp-1.1") {
      (Gimp-&gt;major_version==1 &amp;&amp; Gimp-&gt;minor_version&gt;=1) || Gimp-&gt;major_version&gt;1;
   } elsif ($_ eq "gimp-1.2") {
      (Gimp-&gt;major_version==1 &amp;&amp; Gimp-&gt;minor_version&gt;=2) || Gimp-&gt;major_version&gt;1;
   } elsif ($_ eq "gimp-1.3") {
      (Gimp-&gt;major_version==1 &amp;&amp; Gimp-&gt;minor_version&gt;=3) || Gimp-&gt;major_version&gt;1;

   } elsif ($_ eq "perl-5.005") {
      $] &gt;= 5.005;
   } elsif ($_ eq "pdl") {
      require Gimp::Config; $Gimp::Config{DEFINE1} =~ /HAVE_PDL/;
   } elsif ($_ eq "gnome") {
      eval { require Gnome }; $@ eq "";
   } elsif ($_ eq "gtkxmhtml") {
      eval { require Gtk::XmHTML }; $@ eq "";
   } elsif ($_ eq "dumper") {
      eval { require Data::Dumper }; $@ eq "";
   } elsif ($_ eq "persistency") {
      eval { require Data::Dumper }; $@ eq "";
   } elsif ($_ eq "unix") {
      !{
         MacOS		=&gt; 1,
         MSWin32	=&gt; 1,
         dos		=&gt; 1,
         MSDOS		=&gt; 1,
         os2		=&gt; 1,
         VMS		=&gt; 1,
         RISCOS		=&gt; 1,
         AmigaOS	=&gt; 1,
         utwin		=&gt; 1,
       }-&gt;{$^O};
   } elsif ($_ eq "never") {
      0;
   } else {
      require Gimp;
      Gimp::logger(message =&gt; "unimplemented requirement '$_' (failed)");
      0;
   }
}

sub _missing {
   my ($msg,$function)=@_;
   require Gimp;
   Gimp::logger(message =&gt; "$_[0] is required but not found", function =&gt; $function);
   Gimp::initialized() ? Gimp::quiet_die() : Gimp::xs_exit(Gimp::quiet_main());
}

sub missing {
   local $Gimp::in_query=1;
   &amp;_missing;
}

sub need {
   my ($feature,$function)=@_;
   _missing($description{$feature},$function) unless present $feature;
}

1;
__END__

=head1 NAME

Gimp::Feature - check for specific features to be present before registering the script.

=head1 SYNOPSIS

  use Gimp::Feature;

or

  use Gimp::Feature qw(feature1 feature2 ...);

=head1 DESCRIPTION

This module can be used to check for specific features to be present. This
can be used to deny running the script when neccessary features are not
present. While some features can be checked for at any time, the Gimp::Fu
module offers a nicer way to check for them.

=over 4

=item C&lt;gtk&gt;

checks for the presence of the gtk interface module.

=item C&lt;gtk-1.1&gt;, C&lt;gtk-1.2&gt;

checks for the presence of gtk-1.1 (1.2) or higher.

=item C&lt;perl-5.005&gt;

checks for perl version 5.005 or higher.

=item C&lt;pdl&gt;

checks for the presence of a suitable version of PDL (&gt;=1.9906).

=item C&lt;gnome&gt;

checks for the presence of the Gnome-Perl module.

=item C&lt;gtkxmhtl&gt;

checks for the presence of the Gtk::XmHTML module.

=item C&lt;unix&gt;

checks wether the script runs on a unix-like operating system. At the
moment, this is every system except windows, macos, os2 and vms.

=item C&lt;persistency&gt;

checks wether the C&lt;Gimp::Data&gt; module (L&lt;Gimp::Data&gt;) can handle complex
persistent data structures, i.e. perl references in addition to plain
strings.

=back

The following features can only be checked B&lt;after&gt; C&lt;Gimp-&gt;main&gt; has been
called (usually found in the form C&lt;exit main&gt;). See L&lt;Gimp::Fu&gt; on how to
check for these.

=over 4

=item C&lt;gimp-1.1&gt;, C&lt;gimp-1.2&gt;

checks for the presense of gimp in at least version 1.1 (1.2).

=back

=head2 FUNCTIONS

=over 4

=item present(feature)

Checks for the presense of the single feature given as the
argument. Returns true if the feature is present, false otherwise.

=item need(feature,[function-name])

Require a specific feature. If the required feature is not present the
program will exit gracefully, logging an appropriate message. You can
optionally supply a function name to further specify the place where this
feature was missing.

This is the function used when importing symbols from the module.

=item missing(feature-description,[function-name])
   
Indicates that a generic feature (described by the first argument) is
missing. A function name can further be specified. This function will log
the given message and exit gracefully.

=item describe(feature)

Returns a string describing the given feature in more detail, or undef if
there is no description for this feature.

=item list()

Returns a list of features that can be checked for. This list might not be
complete.

=back

=head1 AUTHOR

Marc Lehmann &lt;pcg@goof.com&gt;

=head1 SEE ALSO

perl(1), Gimp(1).

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