Sort::Maker: (Notes) The plain and the orcish don"t include the "init_code"
am 14.12.2006 13:32:06 von paduille.4060.mumia.wHello everybody.
I'm running the following program:
----------program----------
#!/usr/bin/perl
use strict;
use warnings;
use Sort::Maker qw(make_sorter sorter_source);
my $sorter = make_sorter (
plain =>
init_code => 'my $try;',
string => '$_',
);
die($@) unless $sorter;
print sorter_source($sorter);
----------end--------------
The output I get is this:
-----------output-----------
sub {
sort {
do{ my( $left, $right ) = map { $_ } $a, $b;
$left cmp $right }
} @_ ;
}
-----------end--------------
Notice that the "init_code" of "my $try;" is missing from the sorting
routine. This bug happens for both the plain and the orcish style
sorters; the ST and GRT sorters work as expected.
Here is a diff that should fix this as well as a couple of other things:
---------------diff--------------
*** Maker.src Wed Dec 6 06:27:46 2006
--- Maker.pm Thu Dec 14 06:18:31 2006
***************
*** 8,14 ****
%EXPORT_TAGS = ( 'all' => [ qw( sorter_source ), @EXPORT ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
! $VERSION = '0.05';
use strict;
--- 8,14 ----
%EXPORT_TAGS = ( 'all' => [ qw( sorter_source ), @EXPORT ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
! $VERSION = '0.06';
use strict;
***************
*** 29,34 ****
--- 29,35 ----
signed_float
unsigned_float
varying
+ closure
) ;
my @value_attrs = qw(
***************
*** 72,77 ****
--- 73,79 ----
my @value_args = qw(
name
init_code
+ style
) ;
# all the attributes can be set with defaults
***************
*** 448,453 ****
--- 450,456 ----
my $source = <
sub {
+ $options->{init_code}
$open_bracket
sort {
$compare_source
***************
*** 507,512 ****
--- 510,516 ----
my $source = <
sub {
+ $options->{init_code}
my ( $cache_dcl ) ;
$open_bracket
***************
*** 1029,1034 ****
--- 1033,1047 ----
perl t/init_code.t -bench
+ =head3 C
+
+ This tells Sort::Maker to not deparse the CODE reference you give
+ it but instead to use it directly. This probably disables some
+ opportunities for optimization of the key extraction code, but it's
+ necessary for situtations where your key extraction code must access
+ lexical variables.
+
+
=head2 Key Description Arguments
Sorting data requires that records be compared in some way so they can
---------------enddiff-----------
I'll try to remember to prefix my Sort::Maker notes and bug reports with
"Sort::Maker (Notes)"
I have no idea what my newsreader does with TAB characters. :-( I hope
it works out. Aioe.org almost certainly does not allow attachments.