Click here to get back home

Sort::Maker: (Notes) The plain and the orcish don't include the "init_code"

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Sort::Maker: (Notes) The plain and the orcish don't include the "init_code" Mumia W. (on aioe) 12-14-2006
Posted by Mumia W. (on aioe) on December 14, 2006, 7:32 am
Please log in for more thread options


Hello 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 } );

! $VERSION = '0.05';

use strict;

--- 8,14 ----
%EXPORT_TAGS = ( 'all' => [ qw( sorter_source ), @EXPORT ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS } );

! $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 ;
sub {
+ $options->
$open_bracket
sort {
$compare_source
***************
*** 507,512 ****
--- 510,516 ----

my $source = <<SUB ;
sub {
+ $options->
my ( $cache_dcl ) ;

$open_bracket
***************
*** 1029,1034 ****
--- 1033,1047 ----

perl t/init_code.t -bench

+ =head3 C<closure>
+
+ 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.



Similar ThreadsPosted
Sort::Maker: style => 'plain' difficulty December 14, 2006, 4:35 am
ANNOUNCE: Sort::Maker .02 September 2, 2004, 5:09 am
Sort::Maker : anonymous sub is compiled outside of my module December 5, 2006, 8:25 am
Accomodate for poor db design using Sort::Maker? December 9, 2006, 12:48 am
proper way to include constants; as module or include file? October 24, 2004, 10:50 pm
Sticky notes page module? July 6, 2006, 1:09 pm
Spreadsheet::ParseExcel : read cell-notes May 27, 2005, 11:54 am
Convert MS-Word to plain text May 9, 2008, 1:29 pm
trying to use HTML::Mason on apache2 but scripts come up as plain text in the browser October 23, 2006, 1:50 am
How to include a connection file in perl December 2, 2006, 3:11 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap