Input: put constants in own module.

This is just much simpler going forward, and a lot less "magic"
happening. Just put the autogenerated code in its own module, instead of
the main one via trickery.
parent 8e6a4e2a
......@@ -11,13 +11,12 @@ use Text::Wrap qw(wrap);
sub gather_files {
my ($self) = @_;
my $code = <<~HEADER;
package Linux::Input::Capabilities; # yes, continue main package
my $code = <<~'HEADER';
package Linux::Input::Capabilities::Constants;
#ABSTRACT: Constants defining various input device capabilities.
use strict;
use warnings qw(all);
our (\@EXPORT, \@EXPORT_OK);
#PODNAME: Linux::Input::Capabilities::AutoGen
#ABSTRACT: Auto-generated portions of L<Linux::Input::Capabilities>
use Exporter qw(import);
our @EXPORT_OK = ('%_REVERSE_TABLE');
HEADER
my $macros = _get_relevant_defines();
......@@ -34,26 +33,27 @@ sub gather_files {
$code .= "\n# Reverse lookup table:\n";
$code .= _macros_to_reverse($macros);
$code .= <<~FOOTER;
$code .= <<~'FOOTER';
1;
=head1 DESCRIPTION
Do not use this directly; this is an implementation detail of
L<Linux::Input::Capabilities> which may change at any point.
This provides constants to use with L<Linux::Input::Capabilities>.
=head1 SEE ALSO
=over 4
=item L<Linux::Input::Capabilities>
This is where to find the documentation.
=back
FOOTER
$self->add_file(
Dist::Zilla::File::InMemory->new(
name => 'lib/Linux/Input/Capabilities/AutoGen.pm',
name => 'lib/Linux/Input/Capabilities/Constants.pm',
content => $code,
)
);
......@@ -153,7 +153,7 @@ can use.
=head1 GENERATED CODE
Code is generated as F<lib/Linux/Input/Capabilities/AutoGen.pm>. It
Code is generated as F<lib/Linux/Input/Capabilities/Constants.pm>. It
consists of three parts:
=over 4
......@@ -181,6 +181,6 @@ given a value.
=item L<Linux::Input::Capabilities>
The public interface to this mass of generated code.
The main interface to this mass of generated code.
=back
......@@ -6,12 +6,9 @@ use warnings;
use Moo;
use Exporter qw(import);
use File::chdir;
use autodie qw(opendir readdir closedir);
use Linux::Input::Capabilities::Dev;
# This adds to *our* EXPORT_OK. Basically this is to avoid having to
# splice generated content into the middle of the human-written module.
use Linux::Input::Capabilities::AutoGen;
use autodie qw(opendir readdir closedir);
use namespace::autoclean;
has sysfs_root => (
is => 'rw',
......@@ -119,15 +116,14 @@ after that, C<$dev_old> and C<$dev_new> may be I<completely different>.
=head1 CONSTANTS
Numerous constants from F<linux/input.h> are exported by this module,
all the ones corresponding the events input devices can produce. They're
named exactly as the C define is; e.g., C<KEY_Y>. There are over 700 of
these, covering keys, buttons, mouse movement, plug/unplug, etc., so
they're not listed here.
Due to how Perl works, you can probably call these constants as class or
instance methods as well. That's untested and unsupported, and may be
removed in the future.
Numerous constants from F<linux/input.h> are exported by
L<Linux::Input::Capabilities::Constants>: all the ones corresponding the
events input devices can produce. They're named exactly as the C define
is; e.g., C<KEY_Y>. There are over 700 of these, covering keys, buttons,
mouse movement, plug/unplug, etc., so they're not listed. (The easiest
way to get a list is to just look at the module source code or its
C<@EXPORT_OK>. Note that also contains underscore-prefixed things which
are only for internal use.)
=head1 SEE ALSO
......
......@@ -8,7 +8,7 @@ use Bit::Vector;
use Carp;
use File::chdir;
use File::Slurper qw(read_text);
use Linux::Input::Capabilities;
use Linux::Input::Capabilities::Constants qw(%_REVERSE_TABLE);
use namespace::autoclean;
use warnings::register;
use autodie qw(opendir readdir closedir);
......@@ -70,7 +70,7 @@ sub get_supported {
unless (exists $self->_decoded->{$type}) {
$self->_decoded->{$type} = [
map $Linux::Input::Capabilities::_REVERSE_TABLE{uc $type}{$_}//"#UNKNOWN#$_",
map $_REVERSE_TABLE{uc $type}{$_} // "#UNKNOWN#$_",
grep $v->contains($_),
0 .. ($v->Size - 1)];
}
......
......@@ -4,7 +4,8 @@ use strict;
use warnings qw(all);
use Config;
use Linux::Input::Capabilities qw(KEY_Y);
use Linux::Input::Capabilities;
use Linux::Input::Capabilities::Constants qw(KEY_Y);
# 32-bit and 64-bit use different formats, unfortunately. It probably
# actually depends on the running kernel, but since we're not actualy
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment