Perl::Critic::Policy::Compatibility::Gtk2Constants(3pm)

Perl::Critic::Policy::Compatibility::Gtk2Constants3pm

New enough gtk2 version for its constants

Overview

This policy is part of the "Perl::Critic::Pulp" add-on. It requires that if you use certain constant subs from "Gtk2" and "Glib" then you must explicitly have a "use" of a high enough version of those modules.

    use Gtk2 1.160;
    ... return Gtk2::EVENT_PROPAGATE;  # bad
    use Gtk2 1.200 ':constants';
    ... return GDK_CURRENT_TIME;       # good

The following "Gtk2" constants are checked,

    GTK_PRIORITY_RESIZE       # new in Gtk2 1.200 (devel 1.190)
    GDK_PRIORITY_EVENTS
    GDK_PRIORITY_REDRAW
    GDK_CURRENT_TIME
    EVENT_PROPAGATE           # new in Gtk2 1.220 (devel 1.210)
    EVENT_STOP
    GTK_PATH_PRIO_LOWEST      # new in Gtk2 1.220 (devel 1.211)
    GTK_PATH_PRIO_GTK
    GTK_PATH_PRIO_APPLICATION
    GTK_PATH_PRIO_THEME
    GTK_PATH_PRIO_RC
    GTK_PATH_PRIO_HIGHEST

and the following "Glib" constants

    SOURCE_CONTINUE           # new in Glib 1.220 (devel 1.210)
    SOURCE_REMOVE

The idea is to keep you from using the constants without a new enough "Gtk2" or "Glib". Of course there's a huge number of other things you might do that also require a new enough version, but these constants tripped me up a few times.

The exact version numbers above and demanded are development versions. You're probably best off rounding up to a "stable" one like 1.200 or 1.220.

As always if you don't care about this and in particular if for instance you only ever use Gtk2 1.220 or higher anyway then you can disable "Gtk2Constants" from your .perlcriticrc in the usual way (see "CONFIGURATION" in Perl::Critic),

    [-Compatibility::Gtk2Constants]

Constant Forms

Constants are recognised as any of for instance

    EVENT_PROPAGATE
    Gtk2::EVENT_PROPAGATE
    Gtk2->EVENT_PROPAGATE
    &EVENT_PROPAGATE
    &Gtk2::EVENT_PROPAGATE

When there's a class name given it's checked, so that other uses of say "EVENT_PROPAGATE" aren't picked up.

    Some::Other::Thing::EVENT_PROPAGATE      # ok
    Some::Other::Thing->EVENT_PROPAGATE      # ok
    &Some::Other::Thing::EVENT_PROPAGATE     # ok

When there's no class name, then it's only assumed to be Gtk2 or Glib when the respective module has been included.

    use Something::Else;
    EVENT_PROPAGATE           # ok
    use Gtk2 ':constants';
    EVENT_PROPAGATE           # bad

In the latter form there's no check for ":constants" or explicit import in the "use", it's assumed that if you've used Gtk2 then "EVENT_PROPAGATE" means that one no matter how the imports might be arranged.

Home page

<http://user42.tuxfamily.org/perl-critic-pulp/index.html>

Releases

4 releases since Debian 10 (Buster); the text changed 1 time.

  1. 10
  2. 11–13

From libperl-critic-pulp-perl 99-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.