[MNDRIX - Thu Jun 23 23:38:48 2005]:
Show quoted text> Some additional keyboard layouts should be added to the 'layout'
> option.
I have attached a patch which will make it easier to register new layouts without changes to
the source. This isn't a cure-all by any means, but it should be a big improvement.
--
rjbs
--- Text-TypingEffort-0.20/lib/Text/TypingEffort.pm 2005-06-26 00:34:36.000000000 -0400
+++ tte/lib/Text/TypingEffort.pm 2005-07-02 16:58:12.000000000 -0400
@@ -62,7 +62,7 @@
layout => 'qwerty' # keyboard layout
| 'dvorak'
| 'aset',
- unknowns => 0 | 1, # tally unknown chars?
+ unknowns => 2 | 1, # tally unknown chars?
initial => \%metrics, # set initial values
);
@@ -375,7 +375,7 @@
############### subroutines to help with the calculations ################
sub _basis {
- my ($desired) = @_;
+ my $desired = shift || 'qwerty';
my %basis;
$basis{LAYOUT} = $desired;
@@ -384,10 +384,7 @@
my @keyboard = &us_104;
# get the layout
- my @layout;
- if( $desired =~ /^dvorak$/i ) { @layout = &dvorak }
- elsif( $desired =~ /^aset$/i ) { @layout = &aset }
- else { @layout = &qwerty }
+ my @layout = @{ layout($desired) };
# get some keyboard characteristics
my($lshift,$rshift) = splice(@keyboard, 0, 2);
@@ -522,12 +519,16 @@
################### subroutines for keyboard layouts ####################
-sub qwerty {
- no warnings 'qw'; # stop warnings about the '#' and ',' characters
- return (
- # the first value is the character generated by pressing the key
- # without any modifier. The second value is the character generated
- # when pressing the key along with the SHIFT key.
+
+my %layout;
+{ no warnings qw(qw); # stop warnings about the '#' and ',' characters
+
+ # the first value is the character generated by pressing the key
+ # without any modifier. The second value is the character generated
+ # when pressing the key along with the SHIFT key.
+ # define the 12345 row
+
+ $layout{qwerty} = [
# define the 12345 row
qw{
` ~
@@ -590,12 +591,9 @@
. >
/ ?
}
- );
-}
+ ];
-sub dvorak {
- no warnings 'qw'; # stop warnings about the '#' and ',' characters
- return (
+ $layout{dvorak} = [
# define the 12345 row
qw/
` ~
@@ -655,15 +653,9 @@
v V
z Z
},
- );
-}
+ ];
-sub aset {
- no warnings 'qw'; # stop warnings about the '#' and ',' characters
- return (
- # the first value is the character generated by pressing the key
- # without any modifier. The second value is the character generated
- # when pressing the key along with the SHIFT key.
+ $layout{aset} = [
# define the 12345 row
qw{
` ~
@@ -726,9 +718,34 @@
. >
/ ?
}
- );
+ ];
}
+=head2 register_layout($layout_name, $layout)
+
+This routine will register a new layout, using the given name. The layout
+itself should be an arrayref containing each key's character and its shifted
+version. (Consult the source for examples.)
+
+=cut
+
+sub register_layout {
+ my ($layout_name, $layout) = @_;
+ $layout{$layout_name} = $layout;
+}
+
+=head2 layout($layout_name)
+
+This routine returns the arrayref representing the requested layout, or the
+QWERTY layout if the given name is unknown.
+
+=cut
+
+sub layout {
+ my ($layout_name) = @_;
+ return $layout{$layout_name} if exists $layout{$layout_name};
+ return $layout{qwerty};
+}
1;
__END__