Text-RecordParser-1.6.5/000755 000765 000024 00000000000 12515526047 015652 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/bin/000755 000765 000024 00000000000 12515526047 016422 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/Changes000644 000765 000024 00000007370 12515526020 017143 0ustar00kyclarkstaff000000 000000 1.6.5 April 21 2015 - Changes to make installation work better, address https://rt.cpan.org/Public/Bug/Display.html?id=54816 1.6.3 August 9 2012 - Fixed bug in "Build.PL" regarding "podselect," updated Build.PL reqs 1.6.2 August 9 2012 - Made output of "tablify -v" prettier using Text::Autoformat 1.6.1 April 30 2013 - Removed a debug statement - Fixed INSTALL 1.6.0 April 30 2013 - Moved to Git repo at github.com:kyclark/text-recordparser.git - Changes to "tablify" - Allow for comment lines - Added more single-letter argument names - Allow for definition of column names 1.5.0 July 21 2010 - Some small changeds to be more defensive about non-existent fields 1.4.0 February 18 2010 - Not sure, but I made a release here 1.3.0 April 20 2009 - Guess record separator based on file extension - Automatically escape single quotes in incoming text for parse_line (resolves RT #34844) - Added "strip-quotes" to tablify (related to RT #40664) - Now more conservative on trimming whitespace from individual fields rather than the whole line (resolves RT #38871) - Added Text::RecordParser::Object (resolves RT #38338) - Added tab2graph 1.2.1 March 6 2006 - Fixed bug in "tablify" that didn't checked definedness of value when printing vertically, added tests and documentation on vertical display 1.1.1 February 21 2006 - Fixed RT bug #17787 submitted by Carl Franks on failed test on Win32 - Fixed RT bug #17788 submitted by Carl Franks on failed test when prereq Text::TabularDisplay is not installed - Fixed off-by-one bug in "--limit" option for "tablify", added test 1.1.0 February 17 2006 - Automatically strip backslash-escaped single quotes (because quotes *must* be escaped to parse) - Added code to "tablify" to display records vertically 1.0.1 February 8 2006 - Fixed a bug in Build.PL that failed to install scripts 1.0.0 December 9 2005 - Fixed bug in "extract" that caused infinite loops when called in a loop context (Sharon Wei) - Added convenience args to "new" ("fs" for "field_separator", "rs" for "record_separator") - Added Text::RecordParser::Tab (convenience class for tab files) - Added back in test for scripts as Text::TabularDisplay 1.21 fixes earlier bug causing tests to fail - Coverted to Module::Build - Now with more test coverage! 0.09 August 2 2005 - Just one arg to "new" means a filename - Removed tests that break with bad version of Text::TabularDisplay 0.08 November 16 2004 - Added "tabmerge" script - Fixed bug in "no-headers" parsing that reordered fields 0.07 September 3 2004 - Bug fixes to whitespace parsing 0.06 April 6 2004 - Added ability to split on whitespace by adding support for regexes as the "field_separator" - Added "trim" method to automatically removed leading and trailing whitespace from fields (to better support parsing of whitespace-separated data) - Improved test suites to run outside of traditional "make test" - Added "tablify" script 0.05 December 16 2003 - Added "quotemeta" to field separator argument to "parse_line" to fix error reported by Olaf Weinert 0.04 November 5 2003 - Added "comment" method to identify lines which should be skipped as comments - Altered "fetchrow_array" to croak if it reads a line but can't parse it into fields, also changed to skip empty lines automatically 0.03 June 27 2003 - Cleaned up "extract" a bit - Allow "new" to accept a single argument and treat as "filename" 0.02 May 6 2003 - Added "data" method to allow reading of data from a scalar - Allow "fetchall_hashref" to use a computed field for the key 0.01 Apr 28 2003 - Created initial version Text-RecordParser-1.6.5/inc/000755 000765 000024 00000000000 12515526047 016423 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/INSTALL000644 000765 000024 00000000123 12515520047 016671 0ustar00kyclarkstaff000000 000000 $ perl Build.PL $ sudo cpanm --installdeps . $ ./Build test $ sudo ./Build install Text-RecordParser-1.6.5/lib/000755 000765 000024 00000000000 12515526047 016420 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/Makefile.PL000644 000765 000024 00000001200 12515521056 017610 0ustar00kyclarkstaff000000 000000 use inc::Module::Install; name 'Text-RecordParser'; abstract 'Parse record-oriented data in a text file'; version_from 'lib/Text/RecordParser.pm'; author 'Ken Youens-Clark '; license 'gpl'; requires 'IO::Scalar'; requires 'Class::Accessor'; requires 'Readonly'; requires 'List::Util'; requires 'List::MoreUtils'; requires 'Text::Autoformat'; build_requires 'Test::More'; build_requires 'Test::Exception'; recommends 'Text::TabularDisplay' => '1.22'; recommends 'GraphViz' => 0; install_script 'bin/tablify'; install_script 'bin/tabmerge'; install_script 'bin/tab2graph'; WriteAll; Text-RecordParser-1.6.5/MANIFEST000644 000765 000024 00000002034 12515521146 016775 0ustar00kyclarkstaff000000 000000 bin/foo.png bin/tab2graph bin/tablify bin/tabmerge Changes inc/Module/Install.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/Scripts.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm INSTALL lib/Text/RecordParser.pm lib/Text/RecordParser/Object.pm lib/Text/RecordParser/Tab.pm Makefile.PL MANIFEST This list of files META.yml README t/00-pipe.t t/01-new.t t/02-filename-fh.t t/03-separator.t t/04-bind.t t/05-fetch.t t/06-filter.t t/07-parse.t t/08-compute.t t/09-comment.t t/10-tablify.t t/11-tabmerge.t t/12-object.t t/13-tab2graph.t t/14-trim.t t/data/bad-file t/data/commented.dat t/data/commented2.dat t/data/empty t/data/merge1.tab t/data/merge2.tab t/data/merge3.tab t/data/numbers.csv t/data/people-no-header.dat t/data/people.dat t/data/pipe.dat t/data/simpsons.alt t/data/simpsons.csv t/data/simpsons.pdd t/data/simpsons.ssv t/data/simpsons.tab t/data/tabular.tab t/data/trim.csv t/pod-coverage.t t/pod.t TODO Text-RecordParser-1.6.5/META.yml000644 000765 000024 00000001366 12515525672 017134 0ustar00kyclarkstaff000000 000000 --- abstract: 'Parse record-oriented data in a text file' author: - 'Ken Youens-Clark ' build_requires: ExtUtils::MakeMaker: 6.36 Test::Exception: 0 Test::More: 0 configure_requires: ExtUtils::MakeMaker: 6.36 distribution_type: module dynamic_config: 1 generated_by: 'Module::Install version 1.14' license: gpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Text-RecordParser no_index: directory: - inc - t recommends: GraphViz: 0 Text::TabularDisplay: '1.22' requires: Class::Accessor: 0 IO::Scalar: 0 List::MoreUtils: 0 List::Util: 0 Readonly: 0 Text::Autoformat: 0 resources: license: http://opensource.org/licenses/gpl-license.php version: '1.006005' Text-RecordParser-1.6.5/README000644 000765 000024 00000032420 12515521075 016527 0ustar00kyclarkstaff000000 000000 NAME Text::RecordParser - read record-oriented files SYNOPSIS use Text::RecordParser; # use default record (\n) and field (,) separators my $p = Text::RecordParser->new( $file ); # or be explicit my $p = Text::RecordParser->new({ filename => $file, field_separator => "\t", }); $p->filename('foo.csv'); # Split records on two newlines $p->record_separator("\n\n"); # Split fields on tabs $p->field_separator("\t"); # Skip lines beginning with hashes $p->comment( qr/^#/ ); # Trim whitespace $p->trim(1); # Use the fields in the first line as column names $p->bind_header; # Get a list of the header fields (in order) my @columns = $p->field_list; # Extract a particular field from the next row my ( $name, $age ) = $p->extract( qw[name age] ); # Return all the fields from the next row my @fields = $p->fetchrow_array; # Define a field alias $p->set_field_alias( name => 'handle' ); # Return all the fields from the next row as a hashref my $record = $p->fetchrow_hashref; print $record->{'name'}; # or print $record->{'handle'}; # Return the record as an object with fields as accessors my $object = $p->fetchrow_object; print $object->name; # or $object->handle; # Get all data as arrayref of arrayrefs my $data = $p->fetchall_arrayref; # Get all data as arrayref of hashrefs my $data = $p->fetchall_arrayref( { Columns => {} } ); # Get all data as hashref of hashrefs my $data = $p->fetchall_hashref('name'); DESCRIPTION This module is for reading record-oriented data in a delimited text file. The most common example have records separated by newlines and fields separated by commas or tabs, but this module aims to provide a consistent interface for handling sequential records in a file however they may be delimited. Typically this data lists the fields in the first line of the file, in which case you should call "bind_header" to bind the field name (or not, and it will be called implicitly). If the first line contains data, you can still bind your own field names via "bind_fields". Either way, you can then use many methods to get at the data as arrays or hashes. METHODS new This is the object constructor. It takes a hash (or hashref) of arguments. Each argument can also be set through the method of the same name. * filename The path to the file being read. If the filename is passed and the fh is not, then it will open a filehandle on that file and sets "fh" accordingly. * comment A compiled regular expression identifying comment lines that should be skipped. * data The data to read. * fh The filehandle of the file to read. * field_separator | fs The field separator (default is comma). * record_separator | rs The record separator (default is newline). * field_filter A callback applied to all the fields as they are read. * header_filter A callback applied to the column names. * trim Boolean to enable trimming of leading and trailing whitespace from fields (useful if splitting on whitespace only). See methods for each argument name for more information. Alternately, if you supply a single argument to "new", it will be treated as the "filename" argument. bind_fields $p->bind_fields( qw[ name rank serial_number ] ); Takes an array of field names and memorizes the field positions for later use. If the input file has no header line but you still wish to retrieve the fields by name (or even if you want to call "bind_header" and then give your own field names), simply pass in the an array of field names you wish to use. Pass in an empty array reference to unset: $p->bind_field( [] ); # unsets fields bind_header $p->bind_header; my $name = $p->extract('name'); Takes the fields from the next row under the cursor and assigns the field names to the values. Usually you would call this immediately after opening the file in order to bind the field names in the first row. comment $p->comment( qr/^#/ ); # Perl-style comments $p->comment( qr/^--/ ); # SQL-style comments Takes a regex to apply to a record to see if it looks like a comment to skip. data $p->data( $string ); $p->data( \$string ); $p->data( @lines ); $p->data( [$line1, $line2, $line3] ); $p->data( IO::File->new('extract( qw[ foo bar baz ] ); Extracts a list of fields out of the last row read. The field names must correspond to the field names bound either via "bind_fields" or "bind_header". fetchrow_array my @values = $p->fetchrow_array; Reads a row from the file and returns an array or array reference of the fields. fetchrow_hashref my $record = $p->fetchrow_hashref; print "Name = ", $record->{'name'}, "\n"; Reads a line of the file and returns it as a hash reference. The keys of the hashref are the field names bound via "bind_fields" or "bind_header". If you do not bind fields prior to calling this method, the "bind_header" method will be implicitly called for you. fetchrow_object while ( my $object = $p->fetchrow_object ) { my $id = $object->id; my $name = $object->naem; # <-- this will throw a runtime error } This will return the next data record as a Text::RecordParser::Object object that has read-only accessor methods of the field names and any aliases. This allows you to enforce field names, further helping ensure that your code is reading the input file correctly. That is, if you are using the "fetchrow_hashref" method to read each line, you may misspell the hash key and introduce a bug in your code. With this method, Perl will throw an error if you attempt to read a field not defined in the file's headers. Additionally, any defined field aliases will be created as additional accessor methods. fetchall_arrayref my $records = $p->fetchall_arrayref; for my $record ( @$records ) { print "Name = ", $record->[0], "\n"; } my $records = $p->fetchall_arrayref( { Columns => {} } ); for my $record ( @$records ) { print "Name = ", $record->{'name'}, "\n"; } Like DBI's fetchall_arrayref, returns an arrayref of arrayrefs. Also accepts optional "{ Columns => {} }" argument to return an arrayref of hashrefs. fetchall_hashref my $records = $p->fetchall_hashref('id'); for my $id ( keys %$records ) { my $record = $records->{ $id }; print "Name = ", $record->{'name'}, "\n"; } Like DBI's fetchall_hashref, this returns a hash reference of hash references. The keys of the top-level hashref are the field values of the field argument you supply. The field name you supply can be a field created by a "field_compute". fh open my $fh, '<', $file or die $!; $p->fh( $fh ); Gets or sets the filehandle of the file being read. field_compute A callback applied to the fields identified by position (or field name if "bind_fields" or "bind_header" was called). The callback will be passed two arguments: 1 The current field 2 A reference to all the other fields, either as an array or hash reference, depending on the method which you called. If data looks like this: parent children Mike Greg,Peter,Bobby Carol Marcia,Jane,Cindy You could split the "children" field into an array reference with the values like so: $p->field_compute( 'children', sub { [ split /,/, shift() ] } ); The field position or name doesn't actually have to exist, which means you could create new, computed fields on-the-fly. E.g., if you data looks like this: 1,3,5 32,4,1 9,5,4 You could write a field_compute like this: $p->field_compute( 3, sub { my ( $cur, $others ) = @_; my $sum; $sum += $_ for @$others; return $sum; } ); Field "3" will be created as the sum of the other fields. This allows you to further write: my $data = $p->fetchall_arrayref; for my $rec ( @$data ) { print "$rec->[0] + $rec->[1] + $rec->[2] = $rec->[3]\n"; } Prints: 1 + 3 + 5 = 9 32 + 4 + 1 = 37 9 + 5 + 4 = 18 field_filter $p->field_filter( sub { $_ = shift; uc(lc($_)) } ); A callback which is applied to each field. The callback will be passed the current value of the field. Whatever is passed back will become the new value of the field. The above example capitalizes field values. To unset the filter, pass in the empty string. field_list $p->bind_fields( qw[ foo bar baz ] ); my @fields = $p->field_list; print join ', ', @fields; # prints "foo, bar, baz" Returns the fields bound via "bind_fields" (or "bind_header"). field_positions my %positions = $p->field_positions; Returns a hash of the fields and their positions bound via "bind_fields" (or "bind_header"). Mostly for internal use. field_separator $p->field_separator("\t"); # splits fields on tabs $p->field_separator('::'); # splits fields on double colons $p->field_separator(qr/\s+/); # splits fields on whitespace my $sep = $p->field_separator; # returns the current separator Gets and sets the token to use as the field delimiter. Regular expressions can be specified using qr//. If not specified, it will take a guess based on the filename extension ("comma" for ".txt," ".dat," or ".csv"; "tab" for ".tab"). The default is a comma. filename $p->filename('/path/to/file.dat'); Gets or sets the complete path to the file to be read. If a file is already opened, then the handle on it will be closed and a new one opened on the new file. get_field_aliases my @aliases = $p->get_field_aliases('name'); Allows you to define alternate names for fields, e.g., sometimes your input file calls city "town" or "township," sometimes a file uses "Moniker" instead of "name." header_filter $p->header_filter( sub { $_ = shift; s/\s+/_/g; lc $_ } ); A callback applied to column header names. The callback will be passed the current value of the header. Whatever is returned will become the new value of the header. The above example collapses spaces into a single underscore and lowercases the letters. To unset a filter, pass in the empty string. record_separator $p->record_separator("\n//\n"); $p->field_separator("\n"); Gets and sets the token to use as the record separator. The default is a newline ("\n"). The above example would read a file that looks like this: field1 field2 field3 // data1 data2 data3 // set_field_alias $p->set_field_alias({ name => 'Moniker,handle', # comma-separated string city => [ qw( town township ) ], # or anonymous arrayref }); Allows you to define alternate names for fields, e.g., sometimes your input file calls city "town" or "township," sometimes a file uses "Moniker" instead of "name." trim my $trim_value = $p->trim(1); Provide "true" argument to remove leading and trailing whitespace from fields. Use a "false" argument to disable. AUTHOR Ken Youens-Clark SOURCE http://github.com/kyclark/text-recordparser CREDITS Thanks to the following: * Benjamin Tilly For Text::xSV, the inspirado for this module * Tim Bunce et al. For DBI, from which many of the methods were shamelessly stolen * Tom Aldcroft For contributing code to make it easy to parse whitespace-delimited data * Liya Ren For catching the column-ordering error when parsing with "no-headers" * Sharon Wei For catching bug in "extract" that sets up infinite loops * Lars Thegler For bug report on missing "script_files" arg in Build.PL BUGS None known. Please use http://rt.cpan.org/ for reporting bugs. LICENSE AND COPYRIGHT Copyright (C) 2006-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Text-RecordParser-1.6.5/t/000755 000765 000024 00000000000 12515526047 016115 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/TODO000644 000765 000024 00000000462 12515520047 016336 0ustar00kyclarkstaff000000 000000 - Some way to control files with a variable number of columns, e.g. foo,bar,baz,quux flim,flam,flom If I want the above parsed into just three fields, would I want: foo,bar,[baz,quux] flim,flam,[flom] Or just: foo,bar,baz flim,flam,flom How would I specify this in the API? Text-RecordParser-1.6.5/t/00-pipe.t000644 000765 000024 00000001315 12515520047 017446 0ustar00kyclarkstaff000000 000000 #!/usr/bin/perl # # test for "field_separator" and "record_separator" # use strict; use FindBin '$Bin'; use Test::More tests => 7; use Text::RecordParser; my $p = Text::RecordParser->new( ); is( $p->field_separator, ',', 'Field separator is comma' ); is( $p->field_separator("\t"), "\t", 'Field separator is tab' ); is( $p->field_separator('::'), '::', 'Field separator is double colon' ); is( ref $p->field_separator(qr/\s+/), 'Regexp', 'Field separator is a regular expression' ); is( $p->record_separator, "\n", 'Record separator is newline' ); is( $p->record_separator("\n\n"), "\n\n", 'Record separator is double newline' ); is( $p->record_separator(':'), ':', 'Record separator is colon' ); Text-RecordParser-1.6.5/t/01-new.t000644 000765 000024 00000005771 12515520047 017315 0ustar00kyclarkstaff000000 000000 #!perl use strict; use File::Spec::Functions; use FindBin '$Bin'; use Readonly; use Test::Exception; use Test::More tests => 26; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); require_ok( 'Text::RecordParser' ); require_ok( 'Text::RecordParser::Tab' ); # # Vanilla "new," test defaults # { my $p = Text::RecordParser->new; isa_ok( $p, 'Text::RecordParser' ); is( $p->filename, '', 'Filename is blank' ); is( $p->fh, undef, 'Filehandle is undefined' ); is( $p->field_filter, '', 'Field filter is blank' ); is( $p->header_filter, '', 'Header filter is blank' ); is( $p->field_separator, ',', 'Default separator is a comma' ); is( $p->trim, undef, 'Default trim value is undefined' ); } # # New with arguments # { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new($file); is( $p->filename, $file, 'Filename sets OK' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( { filename => $file } ); is( $p->filename, $file, 'Filename as hashref sets OK' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( filename => $file, field_separator => "\t", record_separator => "\n\n", field_filter => sub { $_ = shift; s/ /_/g; $_ }, header_filter => sub { $_ = shift; s/\s+/_/g; lc $_ }, trim => 1, ); is( $p->filename, $file, 'Filename set OK' ); is( $p->field_separator, "\t", 'Field separator is a tab' ); is( $p->record_separator, "\n\n", 'Record separator is two newlines' ); is( ref $p->field_filter, 'CODE', 'Field filter is code' ); is( ref $p->header_filter, 'CODE', 'Header filter is code' ); is( $p->trim, 1, 'Trim mode is on' ); } { my $p = Text::RecordParser->new; is( $p->trim, undef, 'trim with no args is undefined' ); is( $p->trim('foo'), 1, 'trim with non-false arg is true' ); is( $p->trim(''), 0, 'trim with false arg is false' ); } # # New with shortened arguments # { my $p = Text::RecordParser->new({ fs => "\t", rs => "\n\n", }); is( $p->field_separator, "\t", 'Shortened field separator arg OK' ); is( $p->record_separator, "\n\n", 'Shortened record separator arg OK' ); } # # New with too many arguments # { throws_ok { my $p = Text::RecordParser->new( filename => catfile( $TEST_DATA_DIR, 'simpsons.csv' ), data => "foo\tbar\tbaz", ); } qr/too many arguments/, 'new dies because of too many data args'; } # # New with just one arg # { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); is( $p->filename, $file, 'One argument taken as filename' ); } # # New Tab # { my $p = Text::RecordParser::Tab->new; isa_ok( $p, 'Text::RecordParser' ); is( $p->field_separator, "\t", 'New T::RP::Tab has tab for field sep' ); } Text-RecordParser-1.6.5/t/02-filename-fh.t000644 000765 000024 00000013024 12515520047 020666 0ustar00kyclarkstaff000000 000000 #!perl # # tests for "filename," "fh," "data," etc. # use strict; use File::Spec::Functions; use File::Temp qw( tempfile ); use FindBin qw( $Bin ); use IO::File; use Readonly; use Test::Exception; use Test::More tests => 41; use Text::RecordParser; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $p = Text::RecordParser->new; is( $p->filename, '', 'Filename is blank' ); my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); is( $p->filename($file), $file, 'Filename sets OK' ); throws_ok { $p->filename($TEST_DATA_DIR) } qr/cannot use dir/i, 'filename rejects directory for argument'; my $bad_file = catfile( $TEST_DATA_DIR, 'non-existent' ); throws_ok { $p->filename($bad_file) } qr/file does not exist/i, 'filename rejects non-existent file'; my @fields = $p->field_list; ok( @fields, 'Got field list' ); my $file2 = catfile( $TEST_DATA_DIR, 'simpsons.tab' ); $p->filename( $file2 ); my @fields2 = $p->field_list; ok( join(',', @fields) ne join(',', @fields2), 'Field list is flushed when resetting filename' ); } # # Filehandle tests # { my $p = Text::RecordParser->new; my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); open my $fh, '<', $file or die "Read of '$file' failed: $!"; is ( ref $p->fh( $fh ), 'GLOB', 'fh is a filehandle' ); # Cause an error by closing the existing fh. close $fh; my $tabfile = catfile( $TEST_DATA_DIR, 'simpsons.tab' ); open my $fh2, '<', $tabfile or die "Read of '$tabfile' failed: $!"; throws_ok { $p->fh( $fh2 ) } qr/can't close existing/i, 'fh catches bad close'; throws_ok { $p->fh('') } qr/doesn't look like a filehandle/i, 'fh catches bad arg'; my $file3 = catfile( $TEST_DATA_DIR, 'simpsons.cvs'); my $io = IO::File->new( $file3 ); is ( ref $p->fh( $io ), 'GLOB', 'fh is a filehandle' ); } { # cause an error on a closed filehandle my ( $fh, $filename ) = tempfile(); my $p = Text::RecordParser->new( fh => $fh ); close $fh; unlink $filename; my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); throws_ok { $p->filename( $file ) } qr/Can't close previously opened/, 'filename dies trying to close a closed filehandle'; } { # cause an error on a disappearing file my $p = Text::RecordParser->new; my ( $fh, $filename ) = tempfile(); $p->filename( $filename ); close $fh; unlink $filename; throws_ok { my $data = $p->fh } qr/Cannot read '\Q$filename\E'/, 'fh dies on bad file'; } # # Data tests # { my $p = Text::RecordParser->new; throws_ok { $p->data() } qr/without any arguments/, 'data called without args dies'; } { my $p = Text::RecordParser->new; throws_ok { $p->data('') } qr/no usable/i, 'data dies with no usable data'; } { my $p = Text::RecordParser->new; my $scalar = "lname,fname,age\nSmith,Joan,20\nDoe,James,21\n"; $p->data( \$scalar ); $p->bind_header; my @fields = $p->field_list; is( scalar @fields, 3, 'data accepted scalar ref' ); } { my $p = Text::RecordParser->new; $p->data( "lname,fname,age\n", "Smith,Joan,20\nDoe,James,21\n" ); $p->bind_header; my @fields = $p->field_list; is( scalar @fields, 3, 'data accepted an array' ); } { my $p = Text::RecordParser->new; my @array = ( "lname,fname,age\n", "Smith,Joan,20\nDoe,James,21\n" ); $p->data( \@array ); $p->bind_header; my @fields = $p->field_list; is( scalar @fields, 3, 'data accepted an array ref' ); } { my $p = Text::RecordParser->new; my $scalar = "lname,fname,age\nSmith,Joan,20\nDoe,James,21\n"; ok( $p->data( $scalar ), 'data accepts a scalar' ); $p->bind_header; my @fields = $p->field_list; is( $fields[0], 'lname', 'lname field' ); is( $fields[1], 'fname', 'fname field' ); is( $fields[2], 'age', 'age field' ); my $rec = $p->fetchrow_hashref; is( $rec->{'lname'}, 'Smith', 'lname = "Smith"' ); is( $rec->{'fname'}, 'Joan', 'fname = "Joan"' ); is( $rec->{'age'}, '20', 'age = "20"' ); $rec = $p->fetchrow_array; is( $rec->[0], 'Doe', 'lname = "Doe"' ); is( $rec->[1], 'James', 'fname = "James"' ); is( $rec->[2], '21', 'age = "21"' ); $p->data( "name\tinstrument\n", "Miles Davis\ttrumpet\n", "Art Blakey\tdrums\n" ); $p->field_separator("\t"); $p->bind_header; @fields = $p->field_list; is( $fields[0], 'name', 'name field' ); is( $fields[1], 'instrument', 'instrument field' ); $rec = $p->fetchrow_array; is( $rec->[0], 'Miles Davis', 'name = "Miles Davis"' ); is( $rec->[1], 'trumpet', 'instrument = "trumpet"' ); $rec = $p->fetchrow_hashref; is( $rec->{'name'}, 'Art Blakey', 'name = "Art Blakey"' ); is( $rec->{'instrument'}, 'drums', 'instrument = "drums"' ); my $filename = "$Bin/data/simpsons.csv"; open my $fh, "<$filename" or die "Can't read '$filename': $!"; is ( $p->data( $fh ), 1, 'data accepts a filehandle' ); is ( UNIVERSAL::isa( $p->fh, 'GLOB' ), 1, 'fh is a GLOB' ); } { my $p = Text::RecordParser->new( data => "lname,fname,age\nSmith,Joan,20\nDoe,James,21\n" ); $p->bind_header; my @fields = $p->field_list; is( $fields[0], 'lname', 'lname field' ); is( $fields[1], 'fname', 'fname field' ); is( $fields[2], 'age', 'age field' ); my $rec = $p->fetchrow_hashref; is( $rec->{'lname'}, 'Smith', 'lname = "Smith"' ); is( $rec->{'fname'}, 'Joan', 'fname = "Joan"' ); is( $rec->{'age'}, '20', 'age = "20"' ); } Text-RecordParser-1.6.5/t/03-separator.t000644 000765 000024 00000001757 12515520047 020526 0ustar00kyclarkstaff000000 000000 #!perl # # test for "field_separator" and "record_separator" # use strict; use File::Spec::Functions; use FindBin qw( $Bin ); use Test::More tests => 8; use Text::RecordParser; use Readonly; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $p = Text::RecordParser->new; is( $p->field_separator, ',', 'Field separator is comma' ); is( $p->field_separator("\t"), "\t", 'Field separator is tab' ); is( $p->field_separator('::'), '::', 'Field separator is double colon' ); is( ref $p->field_separator(qr/\s+/), 'Regexp', 'Field separator is a regular expression' ); is( $p->record_separator, "\n", 'Record separator is newline' ); is( $p->record_separator("\n\n"), "\n\n", 'Record separator is double newline' ); is( $p->record_separator(':'), ':', 'Record separator is colon' ); } { my $p2 = Text::RecordParser->new(catfile($TEST_DATA_DIR, 'simpsons.tab')); is( $p2->field_separator("\t"), "\t", 'Field separator guessed tab' ); } Text-RecordParser-1.6.5/t/04-bind.t000644 000765 000024 00000004073 12515520047 017435 0ustar00kyclarkstaff000000 000000 #!perl # # tests for "bind_fields" and "bind_header" # use strict; use File::Spec::Functions; use FindBin '$Bin'; use Test::Exception; use Test::More tests => 16; use Text::RecordParser; use Readonly; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $p = Text::RecordParser->new; throws_ok { my @field_list = $p->field_list } qr/no file/i, 'Error on "field_list" with no file'; is( $p->bind_fields(qw[ foo bar baz ]), 1, 'Bind fields successful' ); my @fields = $p->field_list; is( $fields[0], 'foo', 'Field "foo"' ); is( $fields[1], 'bar', 'Field "bar"' ); is( $fields[2], 'baz', 'Field "baz"' ); my $f1 = catfile($TEST_DATA_DIR, 'simpsons.csv'); $p->filename( $f1 ); is( $p->bind_header, 1, 'Bind header successful' ); @fields = $p->field_list; is( $fields[0], 'Name', 'Field "Name"' ); is( $fields[2], 'City', 'Field "City"' ); is( $fields[-1], 'Dependents', 'Field "Dependents"' ); } { my $p = Text::RecordParser->new; throws_ok { $p->bind_fields() } qr/called without field list/i, 'Error on bind_field without args'; } { my $p = Text::RecordParser->new; my %pos1 = $p->field_positions; ok( !%pos1, 'No field positions with unbound headers' ); $p->bind_fields( qw[ foo bar baz ] ); my %pos2 = $p->field_positions; my %should_be = ( foo => 0, bar => 1, baz => 2, ); is_deeply( \%pos2, \%should_be, 'field positions OK' ); } { my $empty_file = catfile( $TEST_DATA_DIR, 'empty' ); my $p = Text::RecordParser->new( $empty_file ); throws_ok { $p->bind_header() } qr/can't find columns in file/i, 'Error on bind_header with empty file'; } { my $p = Text::RecordParser->new; $p->field_separator("\t"); my $f2 = catfile($TEST_DATA_DIR, 'simpsons.tab'); $p->filename( $f2 ); ok( my @fields = $p->field_list, 'bind_header implicitly called' ); is( scalar @fields, 7, 'Found seven fields' ); is( join(',', @fields), 'Name,Address,City,State,Wife,Children,Pets', 'Fields OK'); } Text-RecordParser-1.6.5/t/05-fetch.t000644 000765 000024 00000015471 12515520047 017617 0ustar00kyclarkstaff000000 000000 #!perl # # tests for "extract" and "fetch*" methods # use strict; use File::Spec::Functions; use FindBin '$Bin'; use Readonly; use Test::Exception; use Test::More tests => 38; use Text::RecordParser; use Text::RecordParser::Tab; use Text::RecordParser::Object; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; # Extract nothing my $undef = $p->extract; is( $undef, undef, 'Fetched nothing' ); # Extract one thing my $name = $p->extract('Name'); is( $name, '"Simpson, Homer"', 'Name is "Simpson, Homer"' ); # Extract several things my ( $address, $city ) = $p->extract(qw[ Address City ]); is( $address, '748 Evergreen Terrace', 'Address is "748 Evergreen Terrace"' ); is( $city, 'Springfield', 'City is "Springfield"' ); } { my $file = catfile( $TEST_DATA_DIR, 'empty' ); my $p = Text::RecordParser->new( $file ); throws_ok { my $data = $p->extract( qw[ foo ] ) } qr/Can't find columns/, 'extract dies without bound fields'; $p->bind_fields( qw[ foo bar baz ] ); my $data = $p->extract( qw[ foo ] ); is( $data, undef, 'extract returns undef on read of empty file' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; throws_ok { my $data = $p->extract('non-existent-field') } qr/invalid field/i, 'extract dies on bad field request'; } { my $file = catfile( $TEST_DATA_DIR, 'bad-file' ); my $p = Text::RecordParser->new( $file ); lives_ok { my @row = $p->fetchrow_array } 'fetchrow_array does not die reading unescaped quote'; } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); my $row = $p->fetchrow_hashref; is( $row->{'City'}, 'Springfield', 'fetchrow_hashref works without binding fields' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; my @row = $p->fetchrow_array; is( $row[0], '"Simpson, Homer"', 'Field "Simpson, Homer"' ); is( $row[1], '747 Evergreen Terrace', 'Field "747 Evergreen Terrace"' ); is( $row[-1], q["Bart,Lisa,Maggie,Santa's Little Helper"], 'Correct dependents list' ); my $row = $p->fetchrow_hashref; is( $row->{'Name'}, '"Flanders, Ned"', 'Name is "Flanders, Ned"' ); is( $row->{'City'}, 'Springfield', 'City is "Springfield"' ); is( $row->{'State'}, '', 'State is empty' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->set_field_alias({ Moniker => 'Name,Name', City => [ qw( town township ) ], }); my @aliases = $p->get_field_aliases('City'); is(join(',', @aliases), 'town,township', 'City => town,township'); my $row = $p->fetchrow_hashref; is( $row->{'Moniker'}, '"Simpson, Homer"', 'Moniker alias for Name' ); is( $row->{'town'}, 'Springfield', 'town alias for city' ); is( $row->{'township'}, 'Springfield', 'township alias for city' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; my $data = $p->fetchall_arrayref; is( scalar @$data, 2, 'fetchall_arrayref gets 2 records' ); my $row = $data->[0]; is( $row->[0], '"Simpson, Homer"', 'Field "Simpson, Homer"' ); is( $row->[1], '747 Evergreen Terrace', 'Field "747 Evergreen Terrace"' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv'); my $p = Text::RecordParser->new( $file ); $p->bind_header; my $data = $p->fetchall_arrayref( { Columns => {} } ); is( scalar @$data, 2, 'fetchall_hashref gets 2 records' ); my $row = $data->[1]; is( $row->{'Name'}, '"Flanders, Ned"', 'Name is "Flanders, Ned"' ); is( $row->{'City'}, 'Springfield', 'City is "Springfield"' ); is( $row->{'State'}, '', 'State is empty' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; my $data = $p->fetchall_arrayref('Bad'); is( scalar @$data, 2, 'fetchall_arrayref ignores bad param' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv'); my $p = Text::RecordParser->new( $file ); $p->bind_header; throws_ok { my $data = $p->fetchall_hashref('Bad Field') } qr/Invalid key field/, 'fetchall_hashref dies on bad field'; } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; my $data = $p->fetchall_hashref('Name'); is( scalar keys %$data, 2, 'fetchall_hashref gets 2 records' ); my $row = $data->{'"Simpson, Homer"'}; is( $row->{'Wife'}, 'Marge', 'Wife is "Marge"' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); $p->bind_header; $p->field_compute( 'crazy_name', sub { my ( $field, $others ) = @_; my $name = $others->{'Name'}; $name =~ s/"//g; $name =~ s/^.*,\s+//g; return "Crazy $name!"; } ); my $data = $p->fetchall_hashref('crazy_name'); is( scalar keys %$data, 2, 'fetchall_hashref gets 2 records' ); my $row = $data->{'Crazy Homer!'}; is( $row->{'Wife'}, 'Marge', 'Wife is "Marge"' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.ssv' ); my $p = Text::RecordParser->new( trim => 1, field_separator => qr/\s+/, filename => $file, ); $p->bind_header; my $row = $p->fetchrow_hashref; is( $row->{'Address'}, '747 Evergreen Terrace', 'Address is "747 Evergreen Terrace"' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.pdd' ); my $p = Text::RecordParser->new( trim => 1, field_separator => '|', filename => $file, ); $p->bind_header; my $row = $p->fetchrow_hashref; is( $row->{'Address'}, '747 Evergreen Terrace', 'Address is "747 Evergreen Terrace"' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.tab' ); my $p = Text::RecordParser::Tab->new( $file ); my $row = $p->fetchrow_hashref; is( $row->{'Pets'}, q[Snowball(s),Santa's Little Helper], 'Pets OK (apostrophe backslashed-unescaped)' ); } { my $p = Text::RecordParser->new( { fh => \*DATA } ); my $o1 = $p->fetchrow_object; is( $o1->name, 'moose', 'moose OK' ); my $o2 = $p->fetchrow_object; is( $o2->name, 'poodle', 'poodle OK' ); my $o3 = $p->fetchrow_object; is( $o3, undef, 'No problem reading off the end' ); } __DATA__ name,id moose,1 poodle,2 Text-RecordParser-1.6.5/t/06-filter.t000644 000765 000024 00000003355 12515520047 020012 0ustar00kyclarkstaff000000 000000 #!perl # # tests for "header_filter" and "field_filter" # use strict; use File::Spec::Functions; use FindBin '$Bin'; use Readonly; use Test::Exception; use Test::More tests => 14; use Text::RecordParser; Readonly my $EMPTY_STR => q{}; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $p = Text::RecordParser->new; is( $p->header_filter, $EMPTY_STR, 'Header filter is blank' ); throws_ok { $p->header_filter('foo') } qr/doesn't look like code/, 'Header filter rejects bad argument'; $p->bind_fields( qw[ One Two Three ] ); is( ref $p->header_filter( sub { lc shift } ), 'CODE', 'Header filter takes value' ); is( join(',', $p->field_list), 'one,two,three', 'setting header filter after binding fields changes field names' ); is( $p->header_filter($EMPTY_STR), $EMPTY_STR, 'Header filter resets to nothing' ); is( $p->field_filter, $EMPTY_STR, 'Field filter is blank' ); throws_ok { $p->field_filter('foo') } qr/doesn't look like code/, 'Field filter rejects bad argument'; is( ref $p->field_filter( sub { lc shift } ), 'CODE', 'Field filter takes value' ); is( $p->field_filter($EMPTY_STR), $EMPTY_STR, 'Field filter resets to nothing' ); $p->header_filter( sub { lc shift } ); $p->field_filter( sub { uc shift } ); $p->filename( catfile( $TEST_DATA_DIR, 'simpsons.csv' ) ); $p->bind_header; my @fields = $p->field_list; is( $fields[0], 'name', 'Field "name"' ); is( $fields[2], 'city', 'Field "city"' ); is( $fields[-1], 'dependents', 'Field "dependents"' ); my @row = $p->fetchrow_array; is( $row[2], 'SPRINGFIELD', 'City is "SPRINGFIELD"' ); is( $row[4], 'MARGE', 'Wife is "MARGE"' ); } Text-RecordParser-1.6.5/t/07-parse.t000644 000765 000024 00000002204 12515520047 017630 0ustar00kyclarkstaff000000 000000 #!perl # # tests for alternate parsing # use strict; use File::Spec::Functions; use FindBin qw( $Bin ); use Readonly; use Test::More tests => 4; use Text::RecordParser; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $file = catfile( $TEST_DATA_DIR, 'simpsons.tab' ); my $p = Text::RecordParser->new( filename => $file, field_separator => "\t", ); $p->bind_header; my $row = $p->fetchrow_hashref; is( $row->{'Wife'}, 'Marge', 'Wife is Marge' ); } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.alt' ); my $p = Text::RecordParser->new( filename => $file, field_separator => "\n", record_separator => "\n//\n", ); $p->bind_header; my $row = $p->fetchrow_hashref; is( $row->{'Wife'}, 'Marge', 'Wife is still Marge' ); } { my $file = catfile( $TEST_DATA_DIR, 'pipe.dat' ); my $p = Text::RecordParser->new( filename => $file, field_separator => qr/\|/, ); my $row = $p->fetchrow_array; is( $row->[0], 'MSH', 'First field is "MSH"' ); is( $row->[-1], '2.2', 'Last field is "2.2"' ); } Text-RecordParser-1.6.5/t/08-compute.t000644 000765 000024 00000004037 12515520047 020201 0ustar00kyclarkstaff000000 000000 #!perl # # tests for field and record compute # use strict; use File::Spec::Functions; use FindBin qw( $Bin ); use Readonly; use Test::Exception; use Test::More tests => 9; use Text::RecordParser; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $p = Text::RecordParser->new; throws_ok { $p->field_compute( '', 'foo' ) } qr/no usable field/i, 'field_compute dies on no field name'; } { my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( filename => $file, header_filter => sub { lc shift }, field_filter => sub { $_ = shift; s/^\s+|\s+$//g; s/"//g; $_ }, ); $p->bind_header; throws_ok { $p->field_compute( 'dependents', 'foo' ) } qr/not code/i, 'field_compute rejects not code'; $p->field_compute( 'dependents', sub { [ split /,/, shift() ] } ); $p->field_compute( 'wife', sub { my ( $field, $others ) = @_; my $husband = $others->{'name'} || ''; $husband =~ s/^.*?,\s*//; return $field.', wife of '.$husband; } ); my $row = $p->fetchrow_hashref; my $dependents = $row->{'dependents'}; is( scalar @{ $dependents || [] }, 4, 'Four dependents' ); is( $dependents->[0], 'Bart', 'Firstborn is Bart' ); is( $dependents->[-1], q[Santa's Little Helper], q[Last is Santa's Little Helper] ); is( $row->{'wife'}, 'Marge, wife of Homer', q[Marge is still Homer's wife] ); } { my $file = catfile( $TEST_DATA_DIR, 'numbers.csv' ); my $p = Text::RecordParser->new( $file ); $p->field_compute( 3, sub { my ( $cur, $others ) = @_; my $sum; $sum += $_ for @$others; return $sum; } ); my $data = $p->fetchall_arrayref; my $rec = $data->[0]; is( $rec->[-1], 9, 'Sum is 9' ); $rec = $data->[1]; is( $rec->[-1], 37, 'Sum is 37' ); $rec = $data->[2]; is( $rec->[-1], 18, 'Sum is 18' ); } Text-RecordParser-1.6.5/t/09-comment.t000644 000765 000024 00000002250 12515520047 020163 0ustar00kyclarkstaff000000 000000 #!perl # # tests for skipping records matching a comment regex # use strict; use File::Spec::Functions; use FindBin qw( $Bin ); use Readonly; use Test::Exception; use Test::More tests => 5; use Text::RecordParser; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $p = Text::RecordParser->new; throws_ok { $p->comment('foo') } qr/look like a regex/i, '"comment" rejects non-regex argument'; } { my $file = catfile( $TEST_DATA_DIR, 'commented.dat' ); my $p = Text::RecordParser->new( filename => $file, comment => qr/^#/, ); $p->bind_header; my $row1 = $p->fetchrow_hashref; is( $row1->{'field1'}, 'foo', 'Field is "foo"' ); my $row2 = $p->fetchrow_hashref; is( $row2->{'field2'}, 'bang', 'Field is "bang"' ); } { my $file = catfile( $TEST_DATA_DIR, 'commented2.dat' ); my $p = Text::RecordParser->new( filename => $file, comment => qr/^--/, ); $p->bind_header; my $row1 = $p->fetchrow_hashref; is( $row1->{'field1'}, 'foo', 'Field is "foo"' ); my $row2 = $p->fetchrow_hashref; is( $row2->{'field2'}, 'bang', 'Field is "bang"' ); } Text-RecordParser-1.6.5/t/10-tablify.t000644 000765 000024 00000013033 12515525233 020146 0ustar00kyclarkstaff000000 000000 #!perl use strict; use Config; use FindBin qw( $Bin ); use Readonly; use Test::More; use File::Spec::Functions; Readonly my $TEST_COUNT => 13; Readonly my $PERL => $^X; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); Readonly my $TABLIFY => catfile($Bin, '..', qw/bin tablify/); plan tests => $TEST_COUNT; ok( -e $TABLIFY, 'Script exists' ); SKIP: { eval { require Text::TabularDisplay }; if ($@) { skip 'Text::TabularDisplay not installed', $TEST_COUNT - 1; } my $data = catfile( $TEST_DATA_DIR, 'people.dat' ); ok( -e $data, 'Data file exists' ); my $nh_data = catfile( $TEST_DATA_DIR, 'people-no-header.dat' ); ok( -e $nh_data, 'Other data file exists' ); my @tests = ( { name => 'Field list', args => "--fs ',' -l $data", expected => '+-----------+-----------+ | Field No. | Field | +-----------+-----------+ | 1 | name | | 2 | rank | | 3 | serial_no | | 4 | is_living | | 5 | age | +-----------+-----------+ ' }, { name => 'Select fields by name', args => "--fs ',' -f name,serial_no $data", expected => '+--------+-----------+ | name | serial_no | +--------+-----------+ | George | 190293 | | Dwight | 908348 | | Attila | | | Tojo | | | Tommy | 998110 | +--------+-----------+ 5 records returned ' }, { name => 'Limit', args => "--fs ',' --limit 2 -f name,serial_no $data", expected => '+--------+-----------+ | name | serial_no | +--------+-----------+ | George | 190293 | | Dwight | 908348 | +--------+-----------+ 2 records returned ' }, { name => 'Select fields by position', args => "--fs ',' -f 1-3,5 $data", expected => '+--------+---------+-----------+------+ | name | rank | serial_no | age | +--------+---------+-----------+------+ | George | General | 190293 | 64 | | Dwight | General | 908348 | 75 | | Attila | Hun | | 56 | | Tojo | Emporor | | 87 | | Tommy | General | 998110 | 54 | +--------+---------+-----------+------+ 5 records returned ' }, { name => 'Filter with regex', args => "--fs ',' -w 'serial_no=~/^\\d{6}\$/' $data", expected => '+--------+---------+-----------+-----------+------+ | name | rank | serial_no | is_living | age | +--------+---------+-----------+-----------+------+ | George | General | 190293 | 0 | 64 | | Dwight | General | 908348 | 0 | 75 | | Tommy | General | 998110 | 1 | 54 | +--------+---------+-----------+-----------+------+ 3 records returned ' }, { name => 'Filter with Perl operator', args => "--fs ',' -w 'name eq \"Dwight\"' $data", expected => '+--------+---------+-----------+-----------+------+ | name | rank | serial_no | is_living | age | +--------+---------+-----------+-----------+------+ | Dwight | General | 908348 | 0 | 75 | +--------+---------+-----------+-----------+------+ 1 record returned ' }, { name => 'Combine filter and field selection', args => "--fs ',' -f name -w 'is_living==1' ". "-w 'serial_no>0' $data", expected => '+-------+ | name | +-------+ | Tommy | +-------+ 1 record returned ' }, { name => 'No headers plus filtering by position', args => "--fs ',' --no-headers -w '3 eq \"General\"' $nh_data", expected => '+--------+---------+--------+--------+--------+ | Field1 | Field2 | Field3 | Field4 | Field5 | +--------+---------+--------+--------+--------+ | George | General | 190293 | 0 | 64 | | Dwight | General | 908348 | 0 | 75 | | Tommy | General | 998110 | 1 | 54 | +--------+---------+--------+--------+--------+ 3 records returned ' }, { name => 'Vertical display', args => "--fs ',' -v $data", no_strip => 1, expected => '************ Record 1 ************ name: George rank: General serial_no: 190293 is_living: 0 age : 64 ************ Record 2 ************ name: Dwight rank: General serial_no: 908348 is_living: 0 age : 75 ************ Record 3 ************ name: Attila rank: Hun serial_no: is_living: 0 age : 56 ************ Record 4 ************ name: Tojo rank: Emporor serial_no: is_living: 0 age : 87 ************ Record 5 ************ name: Tommy rank: General serial_no: 998110 is_living: 1 age : 54 5 records returned ' }, { name => 'No headers, vertical display', args => "--fs ',' --no-headers -v --limit 1 $nh_data", no_strip => 1, expected => '************ Record 1 ************ Field1: George Field2: General Field3: 190293 Field4: 0 Field5: 64 1 record returned ' }, ); my $command = "$PERL $TABLIFY "; for my $test ( @tests ) { my $out = `$command $test->{'args'}`; unless ( $test->{'no_strip'} ) { $test->{'expected'} =~ s/^\s*//xmsg; } is( $out, $test->{'expected'}, $test->{'name'} || 'Parsing' ); } }; Text-RecordParser-1.6.5/t/11-tabmerge.t000644 000765 000024 00000007374 12515525622 020320 0ustar00kyclarkstaff000000 000000 #!perl use strict; use Config; use File::Spec::Functions; use FindBin qw( $Bin ); use Readonly; use Test::More tests => 10; Readonly my $PERL => $^X; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); Readonly my $TABMERGE => catfile( $Bin, '..', 'bin', 'tabmerge' ); ok( -e $TABMERGE, 'Script exists' ); SKIP: { eval { require Text::TabularDisplay }; if ($@) { skip 'Text::TabularDisplay not installed', 9; } my @files = map { catfile($TEST_DATA_DIR, "merge${_}.tab") } (1..3); for my $file ( @files ) { ok( -e $file, 'Data file "$file" exists' ); } my $data = join( ' ', @files ); my @tests = ( { name => 'List', args => "--list $data", expected => '+-----------+-------------------+ | Field | No. Times Present | +-----------+-------------------+ | lod_score | 1 | | name | 3 | | position | 3 | | type | 2 | +-----------+-------------------+ ' }, { name => 'Merge min', args => "$data", expected => '+----------+----------+ | name | position | +----------+----------+ | RM104 | 2.30 | | RM105 | 4.5 | | TX5509 | 10.4 | | UU189 | 19.0 | | Xpsm122 | 3.3 | | Xpsr9556 | 4.5 | | DRTL | 2.30 | | ALTX | 4.5 | | DWRF | 10.4 | +----------+----------+ ' }, { name => 'Merge max', args => "--max $data", expected => '+-----------+----------+----------+--------+ | lod_score | name | position | type | +-----------+----------+----------+--------+ | | RM104 | 2.30 | RFLP | | | RM105 | 4.5 | RFLP | | | TX5509 | 10.4 | AFLP | | 2.4 | UU189 | 19.0 | SSR | | 1.2 | Xpsm122 | 3.3 | Marker | | 1.2 | Xpsr9556 | 4.5 | Marker | | | DRTL | 2.30 | | | | ALTX | 4.5 | | | | DWRF | 10.4 | | +-----------+----------+----------+--------+ ' }, { name => 'Merge on named fields', args => "-f name,type $data", expected => '+----------+--------+ | name | type | +----------+--------+ | RM104 | RFLP | | RM105 | RFLP | | TX5509 | AFLP | | UU189 | SSR | | Xpsm122 | Marker | | Xpsr9556 | Marker | | DRTL | | | ALTX | | | DWRF | | +----------+--------+ ' }, { name => 'Merge on named fields and sort', args => "-f name,lod_score -s name $data", expected => '+----------+-----------+ | name | lod_score | +----------+-----------+ | ALTX | | | DRTL | | | DWRF | | | RM104 | | | RM105 | | | TX5509 | | | UU189 | 2.4 | | Xpsm122 | 1.2 | | Xpsr9556 | 1.2 | +----------+-----------+ ' }, { name => 'Merge on named fields and sort, print stdout', args => "-f name,lod_score -s name --stdout $data", expected => 'name lod_score ALTX DRTL DWRF RM104 RM105 TX5509 UU189 2.4 Xpsm122 1.2 Xpsr9556 1.2 ' }, ); my $command = "$PERL $TABMERGE "; for my $test ( @tests ) { my $out = `$command $test->{'args'}`; $test->{'expected'} =~ s/^\s+//xmsg; is( $out, $test->{'expected'}, $test->{'name'} || 'Parsing' ); } }; Text-RecordParser-1.6.5/t/12-object.t000644 000765 000024 00000001273 12515520047 017765 0ustar00kyclarkstaff000000 000000 #!perl use strict; use Config; use File::Spec::Functions; use FindBin qw( $Bin ); use Readonly; use Test::Exception; use Test::More tests => 6; use Text::RecordParser; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); require_ok 'Text::RecordParser::Object'; my $file = catfile( $TEST_DATA_DIR, 'simpsons.csv' ); my $p = Text::RecordParser->new( $file ); my $r; ok( $r = $p->fetchrow_object, 'Got object' ); isa_ok( $r, 'Text::RecordParser::Object', 'Correct class' ); ok( $r->can('Address') && 1, 'Has the "Address" method' ); is( $r->Address, '747 Evergreen Terrace', "Address is good"); throws_ok { $r->Address('900 Oakhill Circle') } qr/cannot alter/, "Method is read-only"; Text-RecordParser-1.6.5/t/13-tab2graph.t000644 000765 000024 00000001735 12515525062 020377 0ustar00kyclarkstaff000000 000000 #!perl use strict; use Config; use File::Basename qw( basename ); use File::Spec::Functions; use FindBin qw( $Bin ); use Readonly; use Test::More; Readonly my $TEST_COUNT => 4; Readonly my $PERL => $^X; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); Readonly my $TAB2GRAPH => catfile( $Bin, '..', 'bin', 'tab2graph' ); plan tests => $TEST_COUNT; ok( -e $TAB2GRAPH, 'Script exists' ); SKIP: { eval { require GraphViz }; if ($@) { skip 'GraphViz not installed', $TEST_COUNT - 1; } my $data = catfile( $TEST_DATA_DIR, 'tabular.tab' ); ok( -e $data, 'Data file exists' ); my $out_file = catfile( $Bin, 'foo.png' ); my $command = "$PERL $TAB2GRAPH -c -o $out_file $data 2>&1"; my $out = `$command`; my $basename = basename( $out_file ); is( $out, qq[Image created "$basename."\n], 'Diagnostic OK' ); my $file_size = -s $out_file; ok( $file_size > 0, 'File is correct size' ); unlink $out_file; }; Text-RecordParser-1.6.5/t/14-trim.t000644 000765 000024 00000001614 12515520047 017473 0ustar00kyclarkstaff000000 000000 #!perl # # tests for "trim" # use strict; use File::Spec::Functions; use FindBin '$Bin'; use Readonly; use Test::Exception; use Test::More tests => 4; use Text::RecordParser; use Text::RecordParser::Tab; Readonly my $TEST_DATA_DIR => catdir( $Bin, 'data' ); { my $file = catfile( $TEST_DATA_DIR, 'trim.csv' ); my $p = Text::RecordParser->new( $file ); my $r1 = $p->fetchrow_hashref; is( $r1->{'SerialNumber'}, '1656401 ', 'Serial number OK' ); my $r2 = $p->fetchrow_hashref; is( $r2->{'SerialNumber'}, ' ', 'Blank serial number OK' ); } { my $file = catfile( $TEST_DATA_DIR, 'trim.csv' ); my $p = Text::RecordParser->new( $file ); $p->trim(1); my $r1 = $p->fetchrow_hashref; is( $r1->{'SerialNumber'}, '1656401', 'Serial number OK' ); my $r2 = $p->fetchrow_hashref; is( $r2->{'SerialNumber'}, '', 'Blank serial number OK' ); } Text-RecordParser-1.6.5/t/data/000755 000765 000024 00000000000 12515526047 017026 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/t/pod-coverage.t000644 000765 000024 00000000257 12515520047 020653 0ustar00kyclarkstaff000000 000000 #!perl use Test::More; eval 'use Test::Pod::Coverage 1.04'; if ( $@ ) { plan skip_all => 'Test::Pod::Coverage 1.04 required for POD coverage' } all_pod_coverage_ok(); Text-RecordParser-1.6.5/t/pod.t000644 000765 000024 00000000211 12515520047 017050 0ustar00kyclarkstaff000000 000000 #!perl use Test::More; eval 'use Test::Pod 1.14'; plan skip_all => 'Test::Pod 1.14 required for testing POD' if $@; all_pod_files_ok(); Text-RecordParser-1.6.5/t/data/bad-file000644 000765 000024 00000000066 12515520047 020410 0ustar00kyclarkstaff000000 000000 This,can't,be,read,without,escaping,the,single-quote. Text-RecordParser-1.6.5/t/data/commented.dat000644 000765 000024 00000000140 12515520047 021460 0ustar00kyclarkstaff000000 000000 # this is a comment field1,field2,field3 foo,bar,baz # this is another comment flip,bang,zoowie Text-RecordParser-1.6.5/t/data/commented2.dat000644 000765 000024 00000000142 12515520047 021544 0ustar00kyclarkstaff000000 000000 -- this is a comment field1,field2,field3 foo,bar,baz -- this is another comment flip,bang,zoowie Text-RecordParser-1.6.5/t/data/empty000644 000765 000024 00000000000 12515520047 020067 0ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/t/data/merge1.tab000644 000765 000024 00000000103 12515520047 020662 0ustar00kyclarkstaff000000 000000 name type position RM104 RFLP 2.30 RM105 RFLP 4.5 TX5509 AFLP 10.4 Text-RecordParser-1.6.5/t/data/merge2.tab000644 000765 000024 00000000137 12515520047 020672 0ustar00kyclarkstaff000000 000000 name type position lod_score UU189 SSR 19.0 2.4 Xpsm122 Marker 3.3 1.2 Xpsr9556 Marker 4.5 1.2 Text-RecordParser-1.6.5/t/data/merge3.tab000644 000765 000024 00000000053 12515520047 020670 0ustar00kyclarkstaff000000 000000 name position DRTL 2.30 ALTX 4.5 DWRF 10.4 Text-RecordParser-1.6.5/t/data/numbers.csv000644 000765 000024 00000000023 12515520047 021203 0ustar00kyclarkstaff000000 000000 1,3,5 32,4,1 9,5,4 Text-RecordParser-1.6.5/t/data/people-no-header.dat000644 000765 000024 00000000164 12515520047 022637 0ustar00kyclarkstaff000000 000000 George,General,190293,0,64 Dwight,General,908348,0,75 Attila,Hun,,0,56 Tojo,Emporor,,0,87 Tommy,General,998110,1,54 Text-RecordParser-1.6.5/t/data/people.dat000644 000765 000024 00000000227 12515520047 020777 0ustar00kyclarkstaff000000 000000 name,rank,serial_no,is_living,age George,General,190293,0,64 Dwight,General,908348,0,75 Attila,Hun,,0,56 Tojo,Emporor,,0,87 Tommy,General,998110,1,54 Text-RecordParser-1.6.5/t/data/pipe.dat000644 000765 000024 00000000643 12515520047 020452 0ustar00kyclarkstaff000000 000000 MSH|^~\&|BOSS|01|PC|00|20020715121500||ADT^A02|BOSS20020715815758|P|2.2 EVN|A02|20020715095900||03 PID|0||9354144|2053549|Nachname^iVorname^^^^""|Geburtsname|19470121|M|||Strasse 10^^Wohnort^^27383^""|||||M|L||||||Hamburg|||D|Techniker PV1|0|S|MKG 18^1823|E||MKG 18^ |11^Dr. med. Dr. dent. Christian Schippers|11^Dr. med. Dr. dent. Christian Schippers||||||| | |||2053549|GO96^01|Q|||S||||||||||||||||||||200207150959 Text-RecordParser-1.6.5/t/data/simpsons.alt000644 000765 000024 00000000303 12515520047 021371 0ustar00kyclarkstaff000000 000000 Name Address City State Wife Children // Simpson, Homer 747 Evergreen Terrace Springfield Marge Bart,Lisa,Maggie // Flander, Ned 748 Evergreen Terrace Springfield Maude (deceased) Rod,Todd // Text-RecordParser-1.6.5/t/data/simpsons.csv000644 000765 000024 00000000333 12515520047 021407 0ustar00kyclarkstaff000000 000000 Name,Address,City,State,Wife,Dependents "Simpson, Homer",747 Evergreen Terrace,Springfield,,Marge,"Bart,Lisa,Maggie,Santa's Little Helper" "Flanders, Ned",748 Evergreen Terrace,Springfield,,Maude (deceased),"Rod,Todd" Text-RecordParser-1.6.5/t/data/simpsons.pdd000644 000765 000024 00000000333 12515520047 021363 0ustar00kyclarkstaff000000 000000 Name|Address|City|State|Wife|Dependents "Simpson| Homer"|747 Evergreen Terrace|Springfield||Marge|"Bart|Lisa|Maggie|Santa's Little Helper" "Flanders| Ned"|748 Evergreen Terrace|Springfield||Maude (deceased)|"Rod|Todd" Text-RecordParser-1.6.5/t/data/simpsons.ssv000644 000765 000024 00000000261 12515520047 021427 0ustar00kyclarkstaff000000 000000 Name Address City State "Simpson, Homer" "747 Evergreen Terrace" Springfield MA "Flander, Ned" "748 Evergreen Terrace" Springfield MA Text-RecordParser-1.6.5/t/data/simpsons.tab000644 000765 000024 00000000342 12515520047 021362 0ustar00kyclarkstaff000000 000000 Name Address City State Wife Children Pets Simpson, Homer 747 Evergreen Terrace Springfield Marge Bart,Lisa,Maggie Snowball(s),Santa\'s Little Helper Flander, Ned 748 Evergreen Terrace Springfield Maude (deceased) Rod,Todd Text-RecordParser-1.6.5/t/data/tabular.tab000644 000765 000024 00000000074 12515520047 021143 0ustar00kyclarkstaff000000 000000 data Jimmy Johnny Patty Ken 0 4 10 Casey 8 3 3 Corrie 1 0 2 Text-RecordParser-1.6.5/t/data/trim.csv000644 000765 000024 00000000103 12515520047 020502 0ustar00kyclarkstaff000000 000000 Name,Rank,SerialNumber Gene,Corporal,1656401 Ken,Discharged, Text-RecordParser-1.6.5/lib/Text/000755 000765 000024 00000000000 12515526047 017344 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/lib/Text/RecordParser/000755 000765 000024 00000000000 12515526047 021737 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/lib/Text/RecordParser.pm000644 000765 000024 00000066006 12515525651 022305 0ustar00kyclarkstaff000000 000000 package Text::RecordParser; =head1 NAME Text::RecordParser - read record-oriented files =head1 SYNOPSIS use Text::RecordParser; # use default record (\n) and field (,) separators my $p = Text::RecordParser->new( $file ); # or be explicit my $p = Text::RecordParser->new({ filename => $file, field_separator => "\t", }); $p->filename('foo.csv'); # Split records on two newlines $p->record_separator("\n\n"); # Split fields on tabs $p->field_separator("\t"); # Skip lines beginning with hashes $p->comment( qr/^#/ ); # Trim whitespace $p->trim(1); # Use the fields in the first line as column names $p->bind_header; # Get a list of the header fields (in order) my @columns = $p->field_list; # Extract a particular field from the next row my ( $name, $age ) = $p->extract( qw[name age] ); # Return all the fields from the next row my @fields = $p->fetchrow_array; # Define a field alias $p->set_field_alias( name => 'handle' ); # Return all the fields from the next row as a hashref my $record = $p->fetchrow_hashref; print $record->{'name'}; # or print $record->{'handle'}; # Return the record as an object with fields as accessors my $object = $p->fetchrow_object; print $object->name; # or $object->handle; # Get all data as arrayref of arrayrefs my $data = $p->fetchall_arrayref; # Get all data as arrayref of hashrefs my $data = $p->fetchall_arrayref( { Columns => {} } ); # Get all data as hashref of hashrefs my $data = $p->fetchall_hashref('name'); =head1 DESCRIPTION This module is for reading record-oriented data in a delimited text file. The most common example have records separated by newlines and fields separated by commas or tabs, but this module aims to provide a consistent interface for handling sequential records in a file however they may be delimited. Typically this data lists the fields in the first line of the file, in which case you should call C to bind the field name (or not, and it will be called implicitly). If the first line contains data, you can still bind your own field names via C. Either way, you can then use many methods to get at the data as arrays or hashes. =head1 METHODS =cut use strict; use warnings; use version; use Carp qw( croak ); use IO::Scalar; use List::MoreUtils qw( uniq ); use Readonly; use Text::ParseWords qw( parse_line ); our $VERSION = version->new('1.6.5'); Readonly my $COMMA => q{,}; Readonly my $EMPTY_STR => q{}; Readonly my $NEW_LINE => qq{\n}; Readonly my $PIPE => q{|}; # ---------------------------------------------------------------- sub new { =pod =head2 new This is the object constructor. It takes a hash (or hashref) of arguments. Each argument can also be set through the method of the same name. =over 4 =item * filename The path to the file being read. If the filename is passed and the fh is not, then it will open a filehandle on that file and sets C accordingly. =item * comment A compiled regular expression identifying comment lines that should be skipped. =item * data The data to read. =item * fh The filehandle of the file to read. =item * field_separator | fs The field separator (default is comma). =item * record_separator | rs The record separator (default is newline). =item * field_filter A callback applied to all the fields as they are read. =item * header_filter A callback applied to the column names. =item * trim Boolean to enable trimming of leading and trailing whitespace from fields (useful if splitting on whitespace only). =back See methods for each argument name for more information. Alternately, if you supply a single argument to C, it will be treated as the C argument. =cut my $class = shift; my $args = defined $_[0] && UNIVERSAL::isa( $_[0], 'HASH' ) ? shift : scalar @_ == 1 ? { filename => shift } : { @_ }; my $self = bless {}, $class; if ( my $fs = $args->{'fs'} ) { $args->{'field_separator'} = $fs; delete $args->{'fs'}; } if ( my $rs = $args->{'rs'} ) { $args->{'record_separator'} = $rs; delete $args->{'rs'}; } my $data_handles = 0; for my $arg ( qw[ filename fh header_filter field_filter trim field_separator record_separator data comment ] ) { next if !defined $args->{ $arg }; if ( $arg =~ / \A (filename|fh|data) \Z /xms ) { $data_handles++; } $self->$arg( $args->{ $arg } ); } if ( $data_handles > 1 ) { croak 'Passed too many arguments to read the data. '. 'Please choose only one of "filename," "fh," or "data."' ; } return $self; } # ---------------------------------------------------------------- sub bind_fields { =pod =head2 bind_fields $p->bind_fields( qw[ name rank serial_number ] ); Takes an array of field names and memorizes the field positions for later use. If the input file has no header line but you still wish to retrieve the fields by name (or even if you want to call C and then give your own field names), simply pass in the an array of field names you wish to use. Pass in an empty array reference to unset: $p->bind_field( [] ); # unsets fields =cut my $self = shift; # using an empty arrayref to unset if ( ref $_[0] eq 'ARRAY' && !@{ $_[0] } ) { $self->{'field_pos_ordered'} = []; $self->{'field_pos'} = {}; $self->{'fields_bound'} = 0; } elsif ( @_ ) { my @fields = @_; $self->{'field_pos_ordered'} = [ @fields ]; my %field_pos; for my $i ( 0 .. $#fields ) { next unless $fields[ $i ]; $field_pos{ $fields[ $i ] } = $i; } $self->{'field_pos'} = \%field_pos; $self->{'fields_bound'} = 1; } else { croak 'Bind fields called without field list'; } return 1; } # ---------------------------------------------------------------- sub bind_header { =pod =head2 bind_header $p->bind_header; my $name = $p->extract('name'); Takes the fields from the next row under the cursor and assigns the field names to the values. Usually you would call this immediately after opening the file in order to bind the field names in the first row. =cut my $self = shift; if ( my @columns = $self->fetchrow_array ) { if ( my $filter = $self->header_filter ) { for my $i ( 0 .. $#columns ) { $columns[ $i ] = $filter->( $columns[ $i ] ); } } $self->bind_fields( @columns ); } else { croak q[Can't find columns in file '], $self->filename, q[']; } return 1; } # ---------------------------------------------------------------- sub comment { =pod =head2 comment $p->comment( qr/^#/ ); # Perl-style comments $p->comment( qr/^--/ ); # SQL-style comments Takes a regex to apply to a record to see if it looks like a comment to skip. =cut my $self = shift; if ( my $arg = shift ) { if ( ref $arg ne 'Regexp' ) { croak q[Argument to comment doesn't look like a regex]; } $self->{'comment'} = $arg; } return defined $self->{'comment'} ? $self->{'comment'} : $EMPTY_STR; } # ---------------------------------------------------------------- sub data { =pod =head2 data $p->data( $string ); $p->data( \$string ); $p->data( @lines ); $p->data( [$line1, $line2, $line3] ); $p->data( IO::File->new(' as it will read the entire contents of the file rather than one line at a time if you set it via C. =cut my $self = shift; my $data; if (@_) { my $arg = shift; if ( UNIVERSAL::isa( $arg, 'SCALAR' ) ) { $data = $$arg; } elsif ( UNIVERSAL::isa( $arg, 'ARRAY' ) ) { $data = join $EMPTY_STR, @$arg; } elsif ( UNIVERSAL::isa( $arg, 'GLOB' ) ) { local $/; $data = <$arg>; } elsif ( !ref($arg) && @_ ) { $data = join $EMPTY_STR, $arg, @_; } else { $data = $arg; } } else { croak 'Data called without any arguments'; } if ( $data ) { my $fh = IO::Scalar->new( \$data ); $self->fh( $fh ); } else { croak 'No usable data'; } return 1; } # ---------------------------------------------------------------- sub extract { =pod =head2 extract my ( $foo, $bar, $baz ) = $p->extract( qw[ foo bar baz ] ); Extracts a list of fields out of the last row read. The field names must correspond to the field names bound either via C or C. =cut my $self = shift; my @fields = @_ or return; my %allowed = map { $_, 1 } $self->field_list; my $record = $self->fetchrow_hashref or return; my @data; foreach my $field ( @fields ) { if ( $allowed{ $field } ) { push @data, $record->{ $field }; } else { croak "Invalid field $field for file " . $self->filename . $NEW_LINE . 'Valid fields are: ' . join(', ', $self->field_list) . $NEW_LINE ; } } return scalar @data == 1 ? $data[0] : @data; } # ---------------------------------------------------------------- sub fetchrow_array { =pod =head2 fetchrow_array my @values = $p->fetchrow_array; Reads a row from the file and returns an array or array reference of the fields. =cut my $self = shift; my $fh = $self->fh or croak 'No filename or file handle'; my $comment = $self->comment; local $/ = $self->record_separator; my $line; my $line_no = 0; for ( ;; ) { $line_no++; defined( $line = <$fh> ) or return; chomp $line; next if $comment and $line =~ $comment; $line =~ s/(?field_separator; $separator eq $PIPE and $separator = '\|'; my @fields = map { defined $_ && $_ =~ s/\\'/'/g; $_ } ( ( ref $separator eq 'Regexp' ) ? parse_line( $separator, 0, $line ) : parse_line( $separator, 1, $line ) ); if ( !@fields ) { croak "Error reading line number $line_no:\n$line"; } if ( my $filter = $self->field_filter ) { @fields = map { $filter->( $_ ) } @fields; } if ( $self->trim ) { @fields = map { defined $_ && s/^\s+|\s+$//g; $_ } @fields; } while ( my ( $position, $callback ) = each %{ $self->field_compute } ) { next if $position !~ m/^\d+$/; $fields[ $position ] = $callback->( $fields[ $position ], \@fields ); } return wantarray ? @fields : \@fields; } # ---------------------------------------------------------------- sub fetchrow_hashref { =pod =head2 fetchrow_hashref my $record = $p->fetchrow_hashref; print "Name = ", $record->{'name'}, "\n"; Reads a line of the file and returns it as a hash reference. The keys of the hashref are the field names bound via C or C. If you do not bind fields prior to calling this method, the C method will be implicitly called for you. =cut my $self = shift; my @fields = $self->field_list or return; my @row = $self->fetchrow_array or return; my $i = 0; my %return; for my $field ( @fields ) { next unless defined $row[ $i ]; $return{ $field } = $row[ $i++ ]; if ( my @aliases = $self->get_field_aliases( $field ) ) { $return{ $_ } = $return{ $field } for @aliases; } } while ( my ( $position, $callback ) = each %{ $self->field_compute } ) { $return{ $position } = $callback->( $return{ $position }, \%return ); } return \%return; } # ---------------------------------------------------------------- sub fetchrow_object { =pod =head2 fetchrow_object while ( my $object = $p->fetchrow_object ) { my $id = $object->id; my $name = $object->naem; # <-- this will throw a runtime error } This will return the next data record as a Text::RecordParser::Object object that has read-only accessor methods of the field names and any aliases. This allows you to enforce field names, further helping ensure that your code is reading the input file correctly. That is, if you are using the "fetchrow_hashref" method to read each line, you may misspell the hash key and introduce a bug in your code. With this method, Perl will throw an error if you attempt to read a field not defined in the file's headers. Additionally, any defined field aliases will be created as additional accessor methods. =cut my $self = shift; my $row = $self->fetchrow_hashref or return; my @fields = $self->field_list or return; push @fields, map { $self->get_field_aliases( $_ ) } @fields; return Text::RecordParser::Object->new( \@fields, $row ); } # ---------------------------------------------------------------- sub fetchall_arrayref { =pod =head2 fetchall_arrayref my $records = $p->fetchall_arrayref; for my $record ( @$records ) { print "Name = ", $record->[0], "\n"; } my $records = $p->fetchall_arrayref( { Columns => {} } ); for my $record ( @$records ) { print "Name = ", $record->{'name'}, "\n"; } Like DBI's fetchall_arrayref, returns an arrayref of arrayrefs. Also accepts optional "{ Columns => {} }" argument to return an arrayref of hashrefs. =cut my $self = shift; my %args = defined $_[0] && ref $_[0] eq 'HASH' ? %{ shift() } : @_ % 2 == 0 ? @_ : (); my $method = ref $args{'Columns'} eq 'HASH' ? 'fetchrow_hashref' : 'fetchrow_array'; my @return; while ( my $record = $self->$method() ) { push @return, $record; } return \@return; } # ---------------------------------------------------------------- sub fetchall_hashref { =pod =head2 fetchall_hashref my $records = $p->fetchall_hashref('id'); for my $id ( keys %$records ) { my $record = $records->{ $id }; print "Name = ", $record->{'name'}, "\n"; } Like DBI's fetchall_hashref, this returns a hash reference of hash references. The keys of the top-level hashref are the field values of the field argument you supply. The field name you supply can be a field created by a C. =cut my $self = shift; my $key_field = shift(@_) || return croak('No key field'); my @fields = $self->field_list; my ( %return, $field_ok ); while ( my $record = $self->fetchrow_hashref ) { if ( !$field_ok ) { if ( !exists $record->{ $key_field } ) { croak "Invalid key field: '$key_field'"; } $field_ok = 1; } $return{ $record->{ $key_field } } = $record; } return \%return; } # ---------------------------------------------------------------- sub fh { =pod =head2 fh open my $fh, '<', $file or die $!; $p->fh( $fh ); Gets or sets the filehandle of the file being read. =cut my ( $self, $arg ) = @_; if ( defined $arg ) { if ( ! UNIVERSAL::isa( $arg, 'GLOB' ) ) { croak q[Argument to fh doesn't look like a filehandle]; } if ( defined $self->{'fh'} ) { close $self->{'fh'} or croak "Can't close existing filehandle: $!"; } $self->{'fh'} = $arg; $self->{'filename'} = $EMPTY_STR; } if ( !defined $self->{'fh'} ) { if ( my $file = $self->filename ) { open my $fh, '<', $file or croak "Cannot read '$file': $!"; $self->{'fh'} = $fh; } } return $self->{'fh'}; } # ---------------------------------------------------------------- sub field_compute { =pod =head2 field_compute A callback applied to the fields identified by position (or field name if C or C was called). The callback will be passed two arguments: =over 4 =item 1 The current field =item 2 A reference to all the other fields, either as an array or hash reference, depending on the method which you called. =back If data looks like this: parent children Mike Greg,Peter,Bobby Carol Marcia,Jane,Cindy You could split the "children" field into an array reference with the values like so: $p->field_compute( 'children', sub { [ split /,/, shift() ] } ); The field position or name doesn't actually have to exist, which means you could create new, computed fields on-the-fly. E.g., if you data looks like this: 1,3,5 32,4,1 9,5,4 You could write a field_compute like this: $p->field_compute( 3, sub { my ( $cur, $others ) = @_; my $sum; $sum += $_ for @$others; return $sum; } ); Field "3" will be created as the sum of the other fields. This allows you to further write: my $data = $p->fetchall_arrayref; for my $rec ( @$data ) { print "$rec->[0] + $rec->[1] + $rec->[2] = $rec->[3]\n"; } Prints: 1 + 3 + 5 = 9 32 + 4 + 1 = 37 9 + 5 + 4 = 18 =cut my $self = shift; if ( @_ ) { my ( $position, $callback ) = @_; if ( $position !~ /\S+/ ) { croak 'No usable field name or position'; } if ( ref $callback ne 'CODE' ) { croak 'Callback not code reference'; } $self->{'field_computes'}{ $position } = $callback; } return $self->{'field_computes'} || {}; } # ---------------------------------------------------------------- sub field_filter { =pod =head2 field_filter $p->field_filter( sub { $_ = shift; uc(lc($_)) } ); A callback which is applied to each field. The callback will be passed the current value of the field. Whatever is passed back will become the new value of the field. The above example capitalizes field values. To unset the filter, pass in the empty string. =cut my ( $self, $filter ) = @_; if ( defined $filter ) { if ( $filter eq $EMPTY_STR ) { $self->{'field_filter'} = $EMPTY_STR; # allows nullification } elsif ( ref $filter eq 'CODE' ) { $self->{'field_filter'} = $filter; } else { croak q[Argument to field_filter doesn't look like code]; } } return $self->{'field_filter'} || $EMPTY_STR; } # ---------------------------------------------------------------- sub field_list { =pod =head2 field_list $p->bind_fields( qw[ foo bar baz ] ); my @fields = $p->field_list; print join ', ', @fields; # prints "foo, bar, baz" Returns the fields bound via C (or C). =cut my $self = shift; if ( !$self->{'fields_bound'} ) { $self->bind_header; } if ( ref $self->{'field_pos_ordered'} eq 'ARRAY' ) { return @{ $self->{'field_pos_ordered'} }; } else { croak 'No fields. Call "bind_fields" or "bind_header" first.'; } } # ---------------------------------------------------------------- sub field_positions { =pod =head2 field_positions my %positions = $p->field_positions; Returns a hash of the fields and their positions bound via C (or C). Mostly for internal use. =cut my $self = shift; if ( ref $self->{'field_pos'} eq 'HASH' ) { return %{ $self->{'field_pos'} }; } else { return; } } # ---------------------------------------------------------------- sub field_separator { =pod =head2 field_separator $p->field_separator("\t"); # splits fields on tabs $p->field_separator('::'); # splits fields on double colons $p->field_separator(qr/\s+/); # splits fields on whitespace my $sep = $p->field_separator; # returns the current separator Gets and sets the token to use as the field delimiter. Regular expressions can be specified using qr//. If not specified, it will take a guess based on the filename extension ("comma" for ".txt," ".dat," or ".csv"; "tab" for ".tab"). The default is a comma. =cut my $self = shift; if ( @_ ) { $self->{'field_separator'} = shift; } if ( !$self->{'field_separator'} ) { my $guess; if ( my $filename = $self->filename ) { if ( $filename =~ /\.(csv|txt|dat)$/ ) { $guess = q{,}; } elsif ( $filename =~ /\.tab$/ ) { $guess = qq{\t}; } } if ( $guess ) { $self->{'field_separator'} = $guess; } } return $self->{'field_separator'} || $COMMA; } # ---------------------------------------------------------------- sub filename { =pod =head2 filename $p->filename('/path/to/file.dat'); Gets or sets the complete path to the file to be read. If a file is already opened, then the handle on it will be closed and a new one opened on the new file. =cut my $self = shift; if ( my $filename = shift ) { if ( -d $filename ) { croak "Cannot use directory '$filename' as input source"; } elsif ( -f _ and -r _ ) { if ( my $fh = $self->fh ) { if ( !close($fh) ) { croak "Can't close previously opened filehandle: $!\n"; } $self->{'fh'} = undef; $self->bind_fields([]); } $self->{'filename'} = $filename; } else { croak "Cannot use '$filename' as input source: ", 'file does not exist or is not readable.' ; } } return $self->{'filename'} || $EMPTY_STR; } # ---------------------------------------------------------------- sub get_field_aliases { =pod =head2 get_field_aliases my @aliases = $p->get_field_aliases('name'); Allows you to define alternate names for fields, e.g., sometimes your input file calls city "town" or "township," sometimes a file uses "Moniker" instead of "name." =cut my $self = shift; my $field_name = shift or return; if ( !$self->{'field_alias'} ) { return; } return @{ $self->{'field_alias'}{ $field_name } || [] }; } # ---------------------------------------------------------------- sub header_filter { =pod =head2 header_filter $p->header_filter( sub { $_ = shift; s/\s+/_/g; lc $_ } ); A callback applied to column header names. The callback will be passed the current value of the header. Whatever is returned will become the new value of the header. The above example collapses spaces into a single underscore and lowercases the letters. To unset a filter, pass in the empty string. =cut my ( $self, $filter ) = @_; if ( defined $filter ) { if ( $filter eq $EMPTY_STR ) { $self->{'header_filter'} = $EMPTY_STR; # allows nullification } elsif ( ref $filter eq 'CODE' ) { $self->{'header_filter'} = $filter; if ( my %field_pos = $self->field_positions ) { my @new_order; while ( my ( $field, $order ) = each %field_pos ) { my $xform = $filter->( $field ); $new_order[ $order ] = $xform; } $self->bind_fields( @new_order ); } } else{ croak q[Argument to field_filter doesn't look like code]; } } return $self->{'header_filter'} || $EMPTY_STR; } # ---------------------------------------------------------------- sub record_separator { =pod =head2 record_separator $p->record_separator("\n//\n"); $p->field_separator("\n"); Gets and sets the token to use as the record separator. The default is a newline ("\n"). The above example would read a file that looks like this: field1 field2 field3 // data1 data2 data3 // =cut my $self = shift; if ( @_ ) { $self->{'record_separator'} = shift; } return $self->{'record_separator'} || $NEW_LINE; } # ---------------------------------------------------------------- sub set_field_alias { =pod =head2 set_field_alias $p->set_field_alias({ name => 'Moniker,handle', # comma-separated string city => [ qw( town township ) ], # or anonymous arrayref }); Allows you to define alternate names for fields, e.g., sometimes your input file calls city "town" or "township," sometimes a file uses "Moniker" instead of "name." =cut my $self = shift; my %args = ref $_[0] eq 'HASH' ? %{ $_[0] } : @_; my %is_field = map { $_, 1 } $self->field_list; ARG: while ( my ( $field_name, $aliases ) = each %args ) { if ( ref $aliases ne 'ARRAY' ) { $aliases = [ split(/,/, $aliases) ]; } if ( !$is_field{ $field_name } ) { push @$aliases, $field_name; ( $field_name ) = grep { $is_field{ $_ } } @$aliases; next ARG unless $field_name; } $self->{'field_alias'}{ $field_name } = [ grep { $_ ne $field_name } uniq( @$aliases ) ]; } return 1; } # ---------------------------------------------------------------- sub trim { =pod =head2 trim my $trim_value = $p->trim(1); Provide "true" argument to remove leading and trailing whitespace from fields. Use a "false" argument to disable. =cut my ( $self, $arg ) = @_; if ( defined $arg ) { $self->{'trim'} = $arg ? 1 : 0; } return $self->{'trim'}; } 1; # ---------------------------------------------------------------- # I must Create a System, or be enslav'd by another Man's; # I will not Reason and Compare; my business is to Create. # -- William Blake, "Jerusalem" # ---------------------------------------------------------------- =pod =head1 AUTHOR Ken Youens-Clark Ekclark@cpan.orgE =head1 SOURCE http://github.com/kyclark/text-recordparser =head1 CREDITS Thanks to the following: =over 4 =item * Benjamin Tilly For Text::xSV, the inspirado for this module =item * Tim Bunce et al. For DBI, from which many of the methods were shamelessly stolen =item * Tom Aldcroft For contributing code to make it easy to parse whitespace-delimited data =item * Liya Ren For catching the column-ordering error when parsing with "no-headers" =item * Sharon Wei For catching bug in C that sets up infinite loops =item * Lars Thegler For bug report on missing "script_files" arg in Build.PL =back =head1 BUGS None known. Please use http://rt.cpan.org/ for reporting bugs. =head1 LICENSE AND COPYRIGHT Copyright (C) 2006-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut Text-RecordParser-1.6.5/lib/Text/RecordParser/Object.pm000644 000765 000024 00000004230 12515520047 023474 0ustar00kyclarkstaff000000 000000 package Text::RecordParser::Object; use strict; use warnings; use version; use base qw( Class::Accessor ); our $VERSION = version->new('1.4.0'); sub new { my ( $class, $field_names, $self ) = @_; $class->mk_ro_accessors( @$field_names ); bless $self, $class; return $self; } 1; __END__ # ---------------------------------------------------------------- =pod =head1 NAME Text::RecordParser::Object - read delimited text files as objects =head1 SYNOPSIS my $o = $p->fetchrow_object; my $name = $o->name; =head1 METHOD =head2 new Just call "fetchrow_object" on a Text::RecordParser object to instantiate an object. =head1 DESCRIPTION This module extends the idea of how you interact with delimited text files, allowing you to enforce field names and identify field aliases easily. That is, if you are using the "fetchrow_hashref" method to read each line, you may misspell the hash key and introduce a bug in your code. With this module, Perl will throw an error if you attempt to read a field not defined in the file's headers. Additionally, any defined field aliases will be created as additional accessor methods. As much as I like the full encapsulation of inside-out objects (e.g., as described in _Perl Best Practies_ by Damian Conway and provided by Class::Std), I couldn't figure out a way to dynamically create the class at runtime. Besides, I figure this interface is only for those who want to use the overhead of objects to enforce policy. If you use this module and still access the hash underneath the object, I can't really help you. =head1 SEE ALSO Class::Accessor. =head1 AUTHOR Ken Youens-Clark Ekclark@cpan.orgE =head1 LICENSE AND COPYRIGHT Copyright (C) 2009-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut Text-RecordParser-1.6.5/lib/Text/RecordParser/Tab.pm000644 000765 000024 00000002721 12515520047 022777 0ustar00kyclarkstaff000000 000000 package Text::RecordParser::Tab; use strict; use warnings; use version; use base qw( Text::RecordParser ); our $VERSION = version->new('1.4.0'); # ---------------------------------------------------------------- sub new { my $class = shift; my $self = $class->SUPER::new( @_ ); $self->field_separator("\t"); return $self; } 1; __END__ # ---------------------------------------------------------------- =pod =head1 NAME Text::RecordParser::Tab - read tab-delimited files =head1 SYNOPSIS use Text::RecordParser::Tab; =head1 DESCRIPTION This module is a shortcut for getting a tab-delimited parser. =head2 new Call "new" as normal but without worrying about "field_separator" or "fs." Because this: my $p = Text::RecordParser::Tab->new($file); Is easier to type than this my $p = Text::RecordParser->new( filename => $file, field_separator => "\t", ); =head1 AUTHOR Ken Youens-Clark Ekclark@cpan.orgE =head1 LICENSE AND COPYRIGHT Copyright (C) 2006-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut Text-RecordParser-1.6.5/inc/Module/000755 000765 000024 00000000000 12515526047 017650 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/inc/Module/Install/000755 000765 000024 00000000000 12515526047 021256 5ustar00kyclarkstaff000000 000000 Text-RecordParser-1.6.5/inc/Module/Install.pm000644 000765 000024 00000030217 12515525671 021621 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install; # For any maintainers: # The load order for Module::Install is a bit magic. # It goes something like this... # # IF ( host has Module::Install installed, creating author mode ) { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install # 3. The installed version of inc::Module::Install loads # 4. inc::Module::Install calls "require Module::Install" # 5. The ./inc/ version of Module::Install loads # } ELSE { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install # 3. The ./inc/ version of Module::Install loads # } use 5.006; use strict 'vars'; use Cwd (); use File::Find (); use File::Path (); use vars qw{$VERSION $MAIN}; BEGIN { # All Module::Install core packages now require synchronised versions. # This will be used to ensure we don't accidentally load old or # different versions of modules. # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. $VERSION = '1.14'; # Storage for the pseudo-singleton $MAIN = undef; *inc::Module::Install::VERSION = *VERSION; @inc::Module::Install::ISA = __PACKAGE__; } sub import { my $class = shift; my $self = $class->new(@_); my $who = $self->_caller; #------------------------------------------------------------- # all of the following checks should be included in import(), # to allow "eval 'require Module::Install; 1' to test # installation of Module::Install. (RT #51267) #------------------------------------------------------------- # Whether or not inc::Module::Install is actually loaded, the # $INC{inc/Module/Install.pm} is what will still get set as long as # the caller loaded module this in the documented manner. # If not set, the caller may NOT have loaded the bundled version, and thus # they may not have a MI version that works with the Makefile.PL. This would # result in false errors or unexpected behaviour. And we don't want that. my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; unless ( $INC{$file} ) { die <<"END_DIE" } Please invoke ${\__PACKAGE__} with: use inc::${\__PACKAGE__}; not: use ${\__PACKAGE__}; END_DIE # This reportedly fixes a rare Win32 UTC file time issue, but # as this is a non-cross-platform XS module not in the core, # we shouldn't really depend on it. See RT #24194 for detail. # (Also, this module only supports Perl 5.6 and above). eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006; # If the script that is loading Module::Install is from the future, # then make will detect this and cause it to re-run over and over # again. This is bad. Rather than taking action to touch it (which # is unreliable on some platforms and requires write permissions) # for now we should catch this and refuse to run. if ( -f $0 ) { my $s = (stat($0))[9]; # If the modification time is only slightly in the future, # sleep briefly to remove the problem. my $a = $s - time; if ( $a > 0 and $a < 5 ) { sleep 5 } # Too far in the future, throw an error. my $t = time; if ( $s > $t ) { die <<"END_DIE" } Your installer $0 has a modification time in the future ($s > $t). This is known to create infinite loops in make. Please correct this, then run $0 again. END_DIE } # Build.PL was formerly supported, but no longer is due to excessive # difficulty in implementing every single feature twice. if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } Module::Install no longer supports Build.PL. It was impossible to maintain duel backends, and has been deprecated. Please remove all Build.PL files and only use the Makefile.PL installer. END_DIE #------------------------------------------------------------- # To save some more typing in Module::Install installers, every... # use inc::Module::Install # ...also acts as an implicit use strict. $^H |= strict::bits(qw(refs subs vars)); #------------------------------------------------------------- unless ( -f $self->{file} ) { foreach my $key (keys %INC) { delete $INC{$key} if $key =~ /Module\/Install/; } local $^W; require "$self->{path}/$self->{dispatch}.pm"; File::Path::mkpath("$self->{prefix}/$self->{author}"); $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); $self->{admin}->init; @_ = ($class, _self => $self); goto &{"$self->{name}::import"}; } local $^W; *{"${who}::AUTOLOAD"} = $self->autoload; $self->preload; # Unregister loader and worker packages so subdirs can use them again delete $INC{'inc/Module/Install.pm'}; delete $INC{'Module/Install.pm'}; # Save to the singleton $MAIN = $self; return 1; } sub autoload { my $self = shift; my $who = $self->_caller; my $cwd = Cwd::getcwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::getcwd(); if ( my $code = $sym->{$pwd} ) { # Delegate back to parent dirs goto &$code unless $cwd eq $pwd; } unless ($$sym =~ s/([^:]+)$//) { # XXX: it looks like we can't retrieve the missing function # via $$sym (usually $main::AUTOLOAD) in this case. # I'm still wondering if we should slurp Makefile.PL to # get some context or not ... my ($package, $file, $line) = caller; die <<"EOT"; Unknown function is found at $file line $line. Execution of $file aborted due to runtime errors. If you're a contributor to a project, you may need to install some Module::Install extensions from CPAN (or other repository). If you're a user of a module, please contact the author. EOT } my $method = $1; if ( uc($method) eq $method ) { # Do nothing return; } elsif ( $method =~ /^_/ and $self->can($method) ) { # Dispatch to the root M:I class return $self->$method(@_); } # Dispatch to the appropriate plugin unshift @_, ( $self, $1 ); goto &{$self->can('call')}; }; } sub preload { my $self = shift; unless ( $self->{extensions} ) { $self->load_extensions( "$self->{prefix}/$self->{path}", $self ); } my @exts = @{$self->{extensions}}; unless ( @exts ) { @exts = $self->{admin}->load_all_extensions; } my %seen; foreach my $obj ( @exts ) { while (my ($method, $glob) = each %{ref($obj) . '::'}) { next unless $obj->can($method); next if $method =~ /^_/; next if $method eq uc($method); $seen{$method}++; } } my $who = $self->_caller; foreach my $name ( sort keys %seen ) { local $^W; *{"${who}::$name"} = sub { ${"${who}::AUTOLOAD"} = "${who}::$name"; goto &{"${who}::AUTOLOAD"}; }; } } sub new { my ($class, %args) = @_; delete $INC{'FindBin.pm'}; { # to suppress the redefine warning local $SIG{__WARN__} = sub {}; require FindBin; } # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); unless ( Cwd::abs_path(Cwd::getcwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; $args{dispatch} ||= 'Admin'; $args{prefix} ||= 'inc'; $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); $args{bundle} ||= 'inc/BUNDLES'; $args{base} ||= $base_path; $class =~ s/^\Q$args{prefix}\E:://; $args{name} ||= $class; $args{version} ||= $class->VERSION; unless ( $args{path} ) { $args{path} = $args{name}; $args{path} =~ s!::!/!g; } $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; $args{wrote} = 0; bless( \%args, $class ); } sub call { my ($self, $method) = @_; my $obj = $self->load($method) or return; splice(@_, 0, 2, $obj); goto &{$obj->can($method)}; } sub load { my ($self, $method) = @_; $self->load_extensions( "$self->{prefix}/$self->{path}", $self ) unless $self->{extensions}; foreach my $obj (@{$self->{extensions}}) { return $obj if $obj->can($method); } my $admin = $self->{admin} or die <<"END_DIE"; The '$method' method does not exist in the '$self->{prefix}' path! Please remove the '$self->{prefix}' directory and run $0 again to load it. END_DIE my $obj = $admin->load($method, 1); push @{$self->{extensions}}, $obj; $obj; } sub load_extensions { my ($self, $path, $top) = @_; my $should_reload = 0; unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) { unshift @INC, $self->{prefix}; $should_reload = 1; } foreach my $rv ( $self->find_extensions($path) ) { my ($file, $pkg) = @{$rv}; next if $self->{pathnames}{$pkg}; local $@; my $new = eval { local $^W; require $file; $pkg->can('new') }; unless ( $new ) { warn $@ if $@; next; } $self->{pathnames}{$pkg} = $should_reload ? delete $INC{$file} : $INC{$file}; push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); } $self->{extensions} ||= []; } sub find_extensions { my ($self, $path) = @_; my @found; File::Find::find( sub { my $file = $File::Find::name; return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; my $subpath = $1; return if lc($subpath) eq lc($self->{dispatch}); $file = "$self->{path}/$subpath.pm"; my $pkg = "$self->{name}::$subpath"; $pkg =~ s!/!::!g; # If we have a mixed-case package name, assume case has been preserved # correctly. Otherwise, root through the file to locate the case-preserved # version of the package name. if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; foreach ( split /\n/, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text next if /^\s*#/; # and comments if ( m/^\s*package\s+($pkg)\s*;/i ) { $pkg = $1; last; } } } push @found, [ $file, $pkg ]; }, $path ) if -d $path; @found; } ##################################################################### # Common Utility Functions sub _caller { my $depth = 0; my $call = caller($depth); while ( $call eq __PACKAGE__ ) { $depth++; $call = caller($depth); } return $call; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _read { local *FH; open( FH, '<', $_[0] ) or die "open($_[0]): $!"; binmode FH; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_NEW sub _read { local *FH; open( FH, "< $_[0]" ) or die "open($_[0]): $!"; binmode FH; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_OLD sub _readperl { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s; $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg; return $string; } sub _readpod { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; return $string if $_[0] =~ /\.pod\z/; $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg; $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg; $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg; $string =~ s/^\n+//s; return $string; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _write { local *FH; open( FH, '>', $_[0] ) or die "open($_[0]): $!"; binmode FH; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_NEW sub _write { local *FH; open( FH, "> $_[0]" ) or die "open($_[0]): $!"; binmode FH; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_OLD # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). sub _version { my $s = shift || 0; my $d =()= $s =~ /(\.)/g; if ( $d >= 2 ) { # Normalise multipart versions $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg; } $s =~ s/^(\d+)\.?//; my $l = $1 || 0; my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g; $l = $l . '.' . join '', @v if @v; return $l + 0; } sub _cmp { _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS sub _CLASS { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s ) ? $_[0] : undef; } 1; # Copyright 2008 - 2012 Adam Kennedy. Text-RecordParser-1.6.5/inc/Module/Install/Base.pm000644 000765 000024 00000002147 12515525671 022474 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { $VERSION = '1.14'; } # Suspend handler for "redefined" warnings BEGIN { my $w = $SIG{__WARN__}; $SIG{__WARN__} = sub { $w }; } #line 42 sub new { my $class = shift; unless ( defined &{"${class}::call"} ) { *{"${class}::call"} = sub { shift->_top->call(@_) }; } unless ( defined &{"${class}::load"} ) { *{"${class}::load"} = sub { shift->_top->load(@_) }; } bless { @_ }, $class; } #line 61 sub AUTOLOAD { local $@; my $func = eval { shift->_top->autoload } or return; goto &$func; } #line 75 sub _top { $_[0]->{_top}; } #line 90 sub admin { $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new; } #line 106 sub is_admin { ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin'); } sub DESTROY {} package Module::Install::Base::FakeAdmin; use vars qw{$VERSION}; BEGIN { $VERSION = $Module::Install::Base::VERSION; } my $fake; sub new { $fake ||= bless(\@_, $_[0]); } sub AUTOLOAD {} sub DESTROY {} # Restore warning handler BEGIN { $SIG{__WARN__} = $SIG{__WARN__}->(); } 1; #line 159 Text-RecordParser-1.6.5/inc/Module/Install/Can.pm000644 000765 000024 00000006157 12515525671 022330 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Can; use strict; use Config (); use ExtUtils::MakeMaker (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # check if we can load some module ### Upgrade this to not have to load the module if possible sub can_use { my ($self, $mod, $ver) = @_; $mod =~ s{::|\\}{/}g; $mod .= '.pm' unless $mod =~ /\.pm$/i; my $pkg = $mod; $pkg =~ s{/}{::}g; $pkg =~ s{\.pm$}{}i; local $@; eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } # Check if we can run some command sub can_run { my ($self, $cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; require File::Spec; my $abs = File::Spec->catfile($dir, $cmd); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # Can our C compiler environment build XS files sub can_xs { my $self = shift; # Ensure we have the CBuilder module $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 ); # Do we have the configure_requires checker? local $@; eval "require ExtUtils::CBuilder;"; if ( $@ ) { # They don't obey configure_requires, so it is # someone old and delicate. Try to avoid hurting # them by falling back to an older simpler test. return $self->can_cc(); } # Do we have a working C compiler my $builder = ExtUtils::CBuilder->new( quiet => 1, ); unless ( $builder->have_compiler ) { # No working C compiler return 0; } # Write a C file representative of what XS becomes require File::Temp; my ( $FH, $tmpfile ) = File::Temp::tempfile( "compilexs-XXXXX", SUFFIX => '.c', ); binmode $FH; print $FH <<'END_C'; #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int main(int argc, char **argv) { return 0; } int boot_sanexs() { return 1; } END_C close $FH; # Can the C compiler access the same headers XS does my @libs = (); my $object = undef; eval { local $^W = 0; $object = $builder->compile( source => $tmpfile, ); @libs = $builder->link( objects => $object, module_name => 'sanexs', ); }; my $result = $@ ? 0 : 1; # Clean up all the build files foreach ( $tmpfile, $object, @libs ) { next unless defined $_; 1 while unlink; } return $result; } # Can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return $self->can_run("@chunks") || (pop(@chunks), next); } return; } # Fix Cygwin bug on maybe_command(); if ( $^O eq 'cygwin' ) { require ExtUtils::MM_Cygwin; require ExtUtils::MM_Win32; if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { *ExtUtils::MM_Cygwin::maybe_command = sub { my ($self, $file) = @_; if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { ExtUtils::MM_Win32->maybe_command($file); } else { ExtUtils::MM_Unix->maybe_command($file); } } } } 1; __END__ #line 236 Text-RecordParser-1.6.5/inc/Module/Install/Fetch.pm000644 000765 000024 00000004627 12515525671 022660 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Fetch; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub get_file { my ($self, %args) = @_; my ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { $args{url} = $args{ftp_url} or (warn("LWP support unavailable!\n"), return); ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; } $|++; print "Fetching '$file' from $host... "; unless (eval { require Socket; Socket::inet_aton($host) }) { warn "'$host' resolve failed!\n"; return; } return unless $scheme eq 'ftp' or $scheme eq 'http'; require Cwd; my $dir = Cwd::getcwd(); chdir $args{local_dir} or return if exists $args{local_dir}; if (eval { require LWP::Simple; 1 }) { LWP::Simple::mirror($args{url}, $file); } elsif (eval { require Net::FTP; 1 }) { eval { # use Net::FTP to get past firewall my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); $ftp->login("anonymous", 'anonymous@example.com'); $ftp->cwd($path); $ftp->binary; $ftp->get($file) or (warn("$!\n"), return); $ftp->quit; } } elsif (my $ftp = $self->can_run('ftp')) { eval { # no Net::FTP, fallback to ftp.exe require FileHandle; my $fh = FileHandle->new; local $SIG{CHLD} = 'IGNORE'; unless ($fh->open("|$ftp -n")) { warn "Couldn't open ftp: $!\n"; chdir $dir; return; } my @dialog = split(/\n/, <<"END_FTP"); open $host user anonymous anonymous\@example.com cd $path binary get $file $file quit END_FTP foreach (@dialog) { $fh->print("$_\n") } $fh->close; } } else { warn "No working 'ftp' program available!\n"; chdir $dir; return; } unless (-f $file) { warn "Fetching failed: $@\n"; chdir $dir; return; } return if exists $args{size} and -s $file != $args{size}; system($args{run}) if exists $args{run}; unlink($file) if $args{remove}; print(((!exists $args{check_for} or -e $args{check_for}) ? "done!" : "failed! ($!)"), "\n"); chdir $dir; return !$?; } 1; Text-RecordParser-1.6.5/inc/Module/Install/Makefile.pm000644 000765 000024 00000027437 12515525671 023350 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Makefile; use strict 'vars'; use ExtUtils::MakeMaker (); use Module::Install::Base (); use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub Makefile { $_[0] } my %seen = (); sub prompt { shift; # Infinite loop protection my @c = caller(); if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; } # In automated testing or non-interactive session, always use defaults if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) { local $ENV{PERL_MM_USE_DEFAULT} = 1; goto &ExtUtils::MakeMaker::prompt; } else { goto &ExtUtils::MakeMaker::prompt; } } # Store a cleaned up version of the MakeMaker version, # since we need to behave differently in a variety of # ways based on the MM version. my $makemaker = eval $ExtUtils::MakeMaker::VERSION; # If we are passed a param, do a "newer than" comparison. # Otherwise, just return the MakeMaker version. sub makemaker { ( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0 } # Ripped from ExtUtils::MakeMaker 6.56, and slightly modified # as we only need to know here whether the attribute is an array # or a hash or something else (which may or may not be appendable). my %makemaker_argtype = ( C => 'ARRAY', CONFIG => 'ARRAY', # CONFIGURE => 'CODE', # ignore DIR => 'ARRAY', DL_FUNCS => 'HASH', DL_VARS => 'ARRAY', EXCLUDE_EXT => 'ARRAY', EXE_FILES => 'ARRAY', FUNCLIST => 'ARRAY', H => 'ARRAY', IMPORTS => 'HASH', INCLUDE_EXT => 'ARRAY', LIBS => 'ARRAY', # ignore '' MAN1PODS => 'HASH', MAN3PODS => 'HASH', META_ADD => 'HASH', META_MERGE => 'HASH', PL_FILES => 'HASH', PM => 'HASH', PMLIBDIRS => 'ARRAY', PMLIBPARENTDIRS => 'ARRAY', PREREQ_PM => 'HASH', CONFIGURE_REQUIRES => 'HASH', SKIP => 'ARRAY', TYPEMAPS => 'ARRAY', XS => 'HASH', # VERSION => ['version',''], # ignore # _KEEP_AFTER_FLUSH => '', clean => 'HASH', depend => 'HASH', dist => 'HASH', dynamic_lib=> 'HASH', linkext => 'HASH', macro => 'HASH', postamble => 'HASH', realclean => 'HASH', test => 'HASH', tool_autosplit => 'HASH', # special cases where you can use makemaker_append CCFLAGS => 'APPENDABLE', DEFINE => 'APPENDABLE', INC => 'APPENDABLE', LDDLFLAGS => 'APPENDABLE', LDFROM => 'APPENDABLE', ); sub makemaker_args { my ($self, %new_args) = @_; my $args = ( $self->{makemaker_args} ||= {} ); foreach my $key (keys %new_args) { if ($makemaker_argtype{$key}) { if ($makemaker_argtype{$key} eq 'ARRAY') { $args->{$key} = [] unless defined $args->{$key}; unless (ref $args->{$key} eq 'ARRAY') { $args->{$key} = [$args->{$key}] } push @{$args->{$key}}, ref $new_args{$key} eq 'ARRAY' ? @{$new_args{$key}} : $new_args{$key}; } elsif ($makemaker_argtype{$key} eq 'HASH') { $args->{$key} = {} unless defined $args->{$key}; foreach my $skey (keys %{ $new_args{$key} }) { $args->{$key}{$skey} = $new_args{$key}{$skey}; } } elsif ($makemaker_argtype{$key} eq 'APPENDABLE') { $self->makemaker_append($key => $new_args{$key}); } } else { if (defined $args->{$key}) { warn qq{MakeMaker attribute "$key" is overriden; use "makemaker_append" to append values\n}; } $args->{$key} = $new_args{$key}; } } return $args; } # For mm args that take multiple space-separated args, # append an argument to the current list. sub makemaker_append { my $self = shift; my $name = shift; my $args = $self->makemaker_args; $args->{$name} = defined $args->{$name} ? join( ' ', $args->{$name}, @_ ) : join( ' ', @_ ); } sub build_subdirs { my $self = shift; my $subdirs = $self->makemaker_args->{DIR} ||= []; for my $subdir (@_) { push @$subdirs, $subdir; } } sub clean_files { my $self = shift; my $clean = $self->makemaker_args->{clean} ||= {}; %$clean = ( %$clean, FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), ); } sub realclean_files { my $self = shift; my $realclean = $self->makemaker_args->{realclean} ||= {}; %$realclean = ( %$realclean, FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), ); } sub libs { my $self = shift; my $libs = ref $_[0] ? shift : [ shift ]; $self->makemaker_args( LIBS => $libs ); } sub inc { my $self = shift; $self->makemaker_args( INC => shift ); } sub _wanted_t { } sub tests_recursive { my $self = shift; my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } my %tests = map { $_ => 1 } split / /, ($self->tests || ''); require File::Find; File::Find::find( sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 }, $dir ); $self->tests( join ' ', sort keys %tests ); } sub write { my $self = shift; die "&Makefile->write() takes no arguments\n" if @_; # Check the current Perl version my $perl_version = $self->perl_version; if ( $perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; } # Make sure we have a new enough MakeMaker require ExtUtils::MakeMaker; if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { # This previous attempted to inherit the version of # ExtUtils::MakeMaker in use by the module author, but this # was found to be untenable as some authors build releases # using future dev versions of EU:MM that nobody else has. # Instead, #toolchain suggests we use 6.59 which is the most # stable version on CPAN at time of writing and is, to quote # ribasushi, "not terminally fucked, > and tested enough". # TODO: We will now need to maintain this over time to push # the version up as new versions are released. $self->build_requires( 'ExtUtils::MakeMaker' => 6.59 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 ); } else { # Allow legacy-compatibility with 5.005 by depending on the # most recent EU:MM that supported 5.005. $self->build_requires( 'ExtUtils::MakeMaker' => 6.36 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 ); } # Generate the MakeMaker params my $args = $self->makemaker_args; $args->{DISTNAME} = $self->name; $args->{NAME} = $self->module_name || $self->name; $args->{NAME} =~ s/-/::/g; $args->{VERSION} = $self->version or die <<'EOT'; ERROR: Can't determine distribution version. Please specify it explicitly via 'version' in Makefile.PL, or set a valid $VERSION in a module, and provide its file path via 'version_from' (or 'all_from' if you prefer) in Makefile.PL. EOT if ( $self->tests ) { my @tests = split ' ', $self->tests; my %seen; $args->{test} = { TESTS => (join ' ', grep {!$seen{$_}++} @tests), }; } elsif ( $Module::Install::ExtraTests::use_extratests ) { # Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness. # So, just ignore our xt tests here. } elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) { $args->{test} = { TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ), }; } if ( $] >= 5.005 ) { $args->{ABSTRACT} = $self->abstract; $args->{AUTHOR} = join ', ', @{$self->author || []}; } if ( $self->makemaker(6.10) ) { $args->{NO_META} = 1; #$args->{NO_MYMETA} = 1; } if ( $self->makemaker(6.17) and $self->sign ) { $args->{SIGN} = 1; } unless ( $self->is_admin ) { delete $args->{SIGN}; } if ( $self->makemaker(6.31) and $self->license ) { $args->{LICENSE} = $self->license; } my $prereq = ($args->{PREREQ_PM} ||= {}); %$prereq = ( %$prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->requires) ); # Remove any reference to perl, PREREQ_PM doesn't support it delete $args->{PREREQ_PM}->{perl}; # Merge both kinds of requires into BUILD_REQUIRES my $build_prereq = ($args->{BUILD_REQUIRES} ||= {}); %$build_prereq = ( %$build_prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->configure_requires, $self->build_requires) ); # Remove any reference to perl, BUILD_REQUIRES doesn't support it delete $args->{BUILD_REQUIRES}->{perl}; # Delete bundled dists from prereq_pm, add it to Makefile DIR my $subdirs = ($args->{DIR} || []); if ($self->bundles) { my %processed; foreach my $bundle (@{ $self->bundles }) { my ($mod_name, $dist_dir) = @$bundle; delete $prereq->{$mod_name}; $dist_dir = File::Basename::basename($dist_dir); # dir for building this module if (not exists $processed{$dist_dir}) { if (-d $dist_dir) { # List as sub-directory to be processed by make push @$subdirs, $dist_dir; } # Else do nothing: the module is already present on the system $processed{$dist_dir} = undef; } } } unless ( $self->makemaker('6.55_03') ) { %$prereq = (%$prereq,%$build_prereq); delete $args->{BUILD_REQUIRES}; } if ( my $perl_version = $self->perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; if ( $self->makemaker(6.48) ) { $args->{MIN_PERL_VERSION} = $perl_version; } } if ($self->installdirs) { warn qq{old INSTALLDIRS (probably set by makemaker_args) is overriden by installdirs\n} if $args->{INSTALLDIRS}; $args->{INSTALLDIRS} = $self->installdirs; } my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_} ) } keys %$args; my $user_preop = delete $args{dist}->{PREOP}; if ( my $preop = $self->admin->preop($user_preop) ) { foreach my $key ( keys %$preop ) { $args{dist}->{$key} = $preop->{$key}; } } my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { my $self = shift; my $makefile_name = shift; my $top_class = ref($self->_top) || ''; my $top_version = $self->_top->VERSION || ''; my $preamble = $self->preamble ? "# Preamble by $top_class $top_version\n" . $self->preamble : ''; my $postamble = "# Postamble by $top_class $top_version\n" . ($self->postamble || ''); local *MAKEFILE; open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; eval { flock MAKEFILE, LOCK_EX }; my $makefile = do { local $/; }; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; # Module::Install will never be used to build the Core Perl # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; # XXX - This is currently unused; not sure if it breaks other MM-users # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; seek MAKEFILE, 0, SEEK_SET; truncate MAKEFILE, 0; print MAKEFILE "$preamble$makefile$postamble" or die $!; close MAKEFILE or die $!; 1; } sub preamble { my ($self, $text) = @_; $self->{preamble} = $text . $self->{preamble} if defined $text; $self->{preamble}; } sub postamble { my ($self, $text) = @_; $self->{postamble} ||= $self->admin->postamble; $self->{postamble} .= $text if defined $text; $self->{postamble} } 1; __END__ #line 544 Text-RecordParser-1.6.5/inc/Module/Install/Metadata.pm000644 000765 000024 00000043302 12515525671 023340 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } my @boolean_keys = qw{ sign }; my @scalar_keys = qw{ name module_name abstract version distribution_type tests installdirs }; my @tuple_keys = qw{ configure_requires build_requires requires recommends bundles resources }; my @resource_keys = qw{ homepage bugtracker repository }; my @array_keys = qw{ keywords author }; *authors = \&author; sub Meta { shift } sub Meta_BooleanKeys { @boolean_keys } sub Meta_ScalarKeys { @scalar_keys } sub Meta_TupleKeys { @tuple_keys } sub Meta_ResourceKeys { @resource_keys } sub Meta_ArrayKeys { @array_keys } foreach my $key ( @boolean_keys ) { *$key = sub { my $self = shift; if ( defined wantarray and not @_ ) { return $self->{values}->{$key}; } $self->{values}->{$key} = ( @_ ? $_[0] : 1 ); return $self; }; } foreach my $key ( @scalar_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} = shift; return $self; }; } foreach my $key ( @array_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} ||= []; push @{$self->{values}->{$key}}, @_; return $self; }; } foreach my $key ( @resource_keys ) { *$key = sub { my $self = shift; unless ( @_ ) { return () unless $self->{values}->{resources}; return map { $_->[1] } grep { $_->[0] eq $key } @{ $self->{values}->{resources} }; } return $self->{values}->{resources}->{$key} unless @_; my $uri = shift or die( "Did not provide a value to $key()" ); $self->resources( $key => $uri ); return 1; }; } foreach my $key ( grep { $_ ne "resources" } @tuple_keys) { *$key = sub { my $self = shift; return $self->{values}->{$key} unless @_; my @added; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @added, [ $module, $version ]; } push @{ $self->{values}->{$key} }, @added; return map {@$_} @added; }; } # Resource handling my %lc_resource = map { $_ => 1 } qw{ homepage license bugtracker repository }; sub resources { my $self = shift; while ( @_ ) { my $name = shift or last; my $value = shift or next; if ( $name eq lc $name and ! $lc_resource{$name} ) { die("Unsupported reserved lowercase resource '$name'"); } $self->{values}->{resources} ||= []; push @{ $self->{values}->{resources} }, [ $name, $value ]; } $self->{values}->{resources}; } # Aliases for build_requires that will have alternative # meanings in some future version of META.yml. sub test_requires { shift->build_requires(@_) } sub install_requires { shift->build_requires(@_) } # Aliases for installdirs options sub install_as_core { $_[0]->installdirs('perl') } sub install_as_cpan { $_[0]->installdirs('site') } sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub dynamic_config { my $self = shift; my $value = @_ ? shift : 1; if ( $self->{values}->{dynamic_config} ) { # Once dynamic we never change to static, for safety return 0; } $self->{values}->{dynamic_config} = $value ? 1 : 0; return 1; } # Convenience command sub static_config { shift->dynamic_config(0); } sub perl_version { my $self = shift; return $self->{values}->{perl_version} unless @_; my $version = shift or die( "Did not provide a value to perl_version()" ); # Normalize the version $version = $self->_perl_version($version); # We don't support the really old versions unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } $self->{values}->{perl_version} = $version; } sub all_from { my ( $self, $file ) = @_; unless ( defined($file) ) { my $name = $self->name or die( "all_from called with no args without setting name() first" ); $file = join('/', 'lib', split(/-/, $name)) . '.pm'; $file =~ s{.*/}{} unless -e $file; unless ( -e $file ) { die("all_from cannot find $file from $name"); } } unless ( -f $file ) { die("The path '$file' does not exist, or is not a file"); } $self->{values}{all_from} = $file; # Some methods pull from POD instead of code. # If there is a matching .pod, use that instead my $pod = $file; $pod =~ s/\.pm$/.pod/i; $pod = $file unless -e $pod; # Pull the different values $self->name_from($file) unless $self->name; $self->version_from($file) unless $self->version; $self->perl_version_from($file) unless $self->perl_version; $self->author_from($pod) unless @{$self->author || []}; $self->license_from($pod) unless $self->license; $self->abstract_from($pod) unless $self->abstract; return 1; } sub provides { my $self = shift; my $provides = ( $self->{values}->{provides} ||= {} ); %$provides = (%$provides, @_) if @_; return $provides; } sub auto_provides { my $self = shift; return $self unless $self->is_admin; unless (-e 'MANIFEST') { warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; return $self; } # Avoid spurious warnings as we are not checking manifest here. local $SIG{__WARN__} = sub {1}; require ExtUtils::Manifest; local *ExtUtils::Manifest::manicheck = sub { return }; require Module::Build; my $build = Module::Build->new( dist_name => $self->name, dist_version => $self->version, license => $self->license, ); $self->provides( %{ $build->find_dist_packages || {} } ); } sub feature { my $self = shift; my $name = shift; my $features = ( $self->{values}->{features} ||= [] ); my $mods; if ( @_ == 1 and ref( $_[0] ) ) { # The user used ->feature like ->features by passing in the second # argument as a reference. Accomodate for that. $mods = $_[0]; } else { $mods = \@_; } my $count = 0; push @$features, ( $name => [ map { ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ } @$mods ] ); return @$features; } sub features { my $self = shift; while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { $self->feature( $name, @$mods ); } return $self->{values}->{features} ? @{ $self->{values}->{features} } : (); } sub no_index { my $self = shift; my $type = shift; push @{ $self->{values}->{no_index}->{$type} }, @_ if $type; return $self->{values}->{no_index}; } sub read { my $self = shift; $self->include_deps( 'YAML::Tiny', 0 ); require YAML::Tiny; my $data = YAML::Tiny::LoadFile('META.yml'); # Call methods explicitly in case user has already set some values. while ( my ( $key, $value ) = each %$data ) { next unless $self->can($key); if ( ref $value eq 'HASH' ) { while ( my ( $module, $version ) = each %$value ) { $self->can($key)->($self, $module => $version ); } } else { $self->can($key)->($self, $value); } } return $self; } sub write { my $self = shift; return $self unless $self->is_admin; $self->admin->write_meta; return $self; } sub version_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->version( ExtUtils::MM_Unix->parse_version($file) ); # for version integrity check $self->makemaker_args( VERSION_FROM => $file ); } sub abstract_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->abstract( bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($file) ); } # Add both distribution and module name sub name_from { my ($self, $file) = @_; if ( Module::Install::_read($file) =~ m/ ^ \s* package \s* ([\w:]+) [\s|;]* /ixms ) { my ($name, $module_name) = ($1, $1); $name =~ s{::}{-}g; $self->name($name); unless ( $self->module_name ) { $self->module_name($module_name); } } else { die("Cannot determine name from $file\n"); } } sub _extract_perl_version { if ( $_[0] =~ m/ ^\s* (?:use|require) \s* v? ([\d_\.]+) \s* ; /ixms ) { my $perl_version = $1; $perl_version =~ s{_}{}g; return $perl_version; } else { return; } } sub perl_version_from { my $self = shift; my $perl_version=_extract_perl_version(Module::Install::_read($_[0])); if ($perl_version) { $self->perl_version($perl_version); } else { warn "Cannot determine perl version info from $_[0]\n"; return; } } sub author_from { my $self = shift; my $content = Module::Install::_read($_[0]); if ($content =~ m/ =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /ixms) { my $author = $1 || $2; # XXX: ugly but should work anyway... if (eval "require Pod::Escapes; 1") { # Pod::Escapes has a mapping table. # It's in core of perl >= 5.9.3, and should be installed # as one of the Pod::Simple's prereqs, which is a prereq # of Pod::Text 3.x (see also below). $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $Pod::Escapes::Name2character_number{$1} ? chr($Pod::Escapes::Name2character_number{$1}) : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) { # Pod::Text < 3.0 has yet another mapping table, # though the table name of 2.x and 1.x are different. # (1.x is in core of Perl < 5.6, 2.x is in core of # Perl < 5.9.3) my $mapping = ($Pod::Text::VERSION < 2) ? \%Pod::Text::HTML_Escapes : \%Pod::Text::ESCAPES; $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $mapping->{$1} ? $mapping->{$1} : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } else { $author =~ s{E}{<}g; $author =~ s{E}{>}g; } $self->author($author); } else { warn "Cannot determine author info from $_[0]\n"; } } #Stolen from M::B my %license_urls = ( perl => 'http://dev.perl.org/licenses/', apache => 'http://apache.org/licenses/LICENSE-2.0', apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1', artistic => 'http://opensource.org/licenses/artistic-license.php', artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', lgpl => 'http://opensource.org/licenses/lgpl-license.php', lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', bsd => 'http://opensource.org/licenses/bsd-license.php', gpl => 'http://opensource.org/licenses/gpl-license.php', gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', mit => 'http://opensource.org/licenses/mit-license.php', mozilla => 'http://opensource.org/licenses/mozilla1.1.php', open_source => undef, unrestricted => undef, restrictive => undef, unknown => undef, ); sub license { my $self = shift; return $self->{values}->{license} unless @_; my $license = shift or die( 'Did not provide a value to license()' ); $license = __extract_license($license) || lc $license; $self->{values}->{license} = $license; # Automatically fill in license URLs if ( $license_urls{$license} ) { $self->resources( license => $license_urls{$license} ); } return 1; } sub _extract_license { my $pod = shift; my $matched; return __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /xms ) || __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /xms ); } sub __extract_license { my $license_text = shift or return; my @phrases = ( '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1, '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1, 'Artistic and GPL' => 'perl', 1, 'GNU general public license' => 'gpl', 1, 'GNU public license' => 'gpl', 1, 'GNU lesser general public license' => 'lgpl', 1, 'GNU lesser public license' => 'lgpl', 1, 'GNU library general public license' => 'lgpl', 1, 'GNU library public license' => 'lgpl', 1, 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, 'LGPL' => 'lgpl', 1, 'BSD' => 'bsd', 1, 'Artistic' => 'artistic', 1, 'MIT' => 'mit', 1, 'Mozilla Public License' => 'mozilla', 1, 'Q Public License' => 'open_source', 1, 'OpenSSL License' => 'unrestricted', 1, 'SSLeay License' => 'unrestricted', 1, 'zlib License' => 'open_source', 1, 'proprietary' => 'proprietary', 0, ); while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s#\s+#\\s+#gs; if ( $license_text =~ /\b$pattern\b/i ) { return $license; } } return ''; } sub license_from { my $self = shift; if (my $license=_extract_license(Module::Install::_read($_[0]))) { $self->license($license); } else { warn "Cannot determine license info from $_[0]\n"; return 'unknown'; } } sub _extract_bugtracker { my @links = $_[0] =~ m#L<( https?\Q://rt.cpan.org/\E[^>]+| https?\Q://github.com/\E[\w_]+/[\w_]+/issues| https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); @links=keys %links; return @links; } sub bugtracker_from { my $self = shift; my $content = Module::Install::_read($_[0]); my @links = _extract_bugtracker($content); unless ( @links ) { warn "Cannot determine bugtracker info from $_[0]\n"; return 0; } if ( @links > 1 ) { warn "Found more than one bugtracker link in $_[0]\n"; return 0; } # Set the bugtracker bugtracker( $links[0] ); return 1; } sub requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->requires( $module => $version ); } } sub test_requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->test_requires( $module => $version ); } } # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to # numbers (eg, 5.006001 or 5.008009). # Also, convert double-part versions (eg, 5.8) sub _perl_version { my $v = $_[-1]; $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e; $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e; $v =~ s/(\.\d\d\d)000$/$1/; $v =~ s/_.+$//; if ( ref($v) ) { # Numify $v = $v + 0; } return $v; } sub add_metadata { my $self = shift; my %hash = @_; for my $key (keys %hash) { warn "add_metadata: $key is not prefixed with 'x_'.\n" . "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/; $self->{values}->{$key} = $hash{$key}; } } ###################################################################### # MYMETA Support sub WriteMyMeta { die "WriteMyMeta has been deprecated"; } sub write_mymeta_yaml { my $self = shift; # We need YAML::Tiny to write the MYMETA.yml file unless ( eval { require YAML::Tiny; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.yml\n"; YAML::Tiny::DumpFile('MYMETA.yml', $meta); } sub write_mymeta_json { my $self = shift; # We need JSON to write the MYMETA.json file unless ( eval { require JSON; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.json\n"; Module::Install::_write( 'MYMETA.json', JSON->new->pretty(1)->canonical->encode($meta), ); } sub _write_mymeta_data { my $self = shift; # If there's no existing META.yml there is nothing we can do return undef unless -f 'META.yml'; # We need Parse::CPAN::Meta to load the file unless ( eval { require Parse::CPAN::Meta; 1; } ) { return undef; } # Merge the perl version into the dependencies my $val = $self->Meta->{values}; my $perl = delete $val->{perl_version}; if ( $perl ) { $val->{requires} ||= []; my $requires = $val->{requires}; # Canonize to three-dot version after Perl 5.6 if ( $perl >= 5.006 ) { $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e } unshift @$requires, [ perl => $perl ]; } # Load the advisory META.yml file my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); my $meta = $yaml[0]; # Overwrite the non-configure dependency hashes delete $meta->{requires}; delete $meta->{build_requires}; delete $meta->{recommends}; if ( exists $val->{requires} ) { $meta->{requires} = { map { @$_ } @{ $val->{requires} } }; } if ( exists $val->{build_requires} ) { $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } }; } return $meta; } 1; Text-RecordParser-1.6.5/inc/Module/Install/Scripts.pm000644 000765 000024 00000001011 12515525671 023236 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Scripts; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub install_script { my $self = shift; my $args = $self->makemaker_args; my $exe = $args->{EXE_FILES} ||= []; foreach ( @_ ) { if ( -f $_ ) { push @$exe, $_; } elsif ( -d 'script' and -f "script/$_" ) { push @$exe, "script/$_"; } else { die("Cannot find script '$_'"); } } } 1; Text-RecordParser-1.6.5/inc/Module/Install/Win32.pm000644 000765 000024 00000003403 12515525671 022520 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::Win32; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # determine if the user needs nmake, and download it if needed sub check_nmake { my $self = shift; $self->load('can_run'); $self->load('get_file'); require Config; return unless ( $^O eq 'MSWin32' and $Config::Config{make} and $Config::Config{make} =~ /^nmake\b/i and ! $self->can_run('nmake') ); print "The required 'nmake' executable not found, fetching it...\n"; require File::Basename; my $rv = $self->get_file( url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', local_dir => File::Basename::dirname($^X), size => 51928, run => 'Nmake15.exe /o > nul', check_for => 'Nmake.exe', remove => 1, ); die <<'END_MESSAGE' unless $rv; ------------------------------------------------------------------------------- Since you are using Microsoft Windows, you will need the 'nmake' utility before installation. It's available at: http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe or ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe Please download the file manually, save it to a directory in %PATH% (e.g. C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to that directory, and run "Nmake15.exe" from there; that will create the 'nmake.exe' file needed by this module. You may then resume the installation process described in README. ------------------------------------------------------------------------------- END_MESSAGE } 1; Text-RecordParser-1.6.5/inc/Module/Install/WriteAll.pm000644 000765 000024 00000002376 12515525671 023351 0ustar00kyclarkstaff000000 000000 #line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.14'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } sub WriteAll { my $self = shift; my %args = ( meta => 1, sign => 0, inline => 0, check_nmake => 1, @_, ); $self->sign(1) if $args{sign}; $self->admin->WriteAll(%args) if $self->is_admin; $self->check_nmake if $args{check_nmake}; unless ( $self->makemaker_args->{PL_FILES} ) { # XXX: This still may be a bit over-defensive... unless ($self->makemaker(6.25)) { $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL'; } } # Until ExtUtils::MakeMaker support MYMETA.yml, make sure # we clean it up properly ourself. $self->realclean_files('MYMETA.yml'); if ( $args{inline} ) { $self->Inline->write; } else { $self->Makefile->write; } # The Makefile write process adds a couple of dependencies, # so write the META.yml files after the Makefile. if ( $args{meta} ) { $self->Meta->write; } # Experimental support for MYMETA if ( $ENV{X_MYMETA} ) { if ( $ENV{X_MYMETA} eq 'JSON' ) { $self->Meta->write_mymeta_json; } else { $self->Meta->write_mymeta_yaml; } } return 1; } 1; Text-RecordParser-1.6.5/bin/foo.png000644 000765 000024 00000101421 12515520047 017704 0ustar00kyclarkstaff000000 000000 PNG  IHDRGJbKGD IDATxy\NWH -R=kv}_k0vƾdKJaagNBENw]}5:uщB!ҥ !B)BtL !"B@!HǤB!ұLիhnܸÿ{>"#_!Y={6s;)9ȟ?7%Jd"*W~77ӑErx0#GqEקxq O\ɟ??FFFdϞ͎ΘD #44;ƢKQVEԩBZUșXw.?̙+9sgp5?~ >Ŋ#O<ʕ333Ȟ=;dΜY@xx8/^ŋ@py!(]krTOREQ3$&&rum;pMf5ښ:uRreʔ)CѢEɐ@rM_ٳg9v(Ν'>>+hݺ!ŋJNK7>}'8y/nuuUFR(Q Htdd$7o͛p)Ξ=/ȝیMkҬY-5AF2H{_ɓs ?(Q;iٲ%HH=ʖ-[ضm+TZ^~cGe3H"}zW`ݺ`aQf͚ӤIԩC9R}fʔߟ3M^zŴip¢+VBu,Juΐ!C5jFFikѣGqr͉'ڵ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غu+66055+WBu$ʖ-Ι3i֬Zb̘1DF7ĉT^={<ٽ{1S" B@˙~L8Q EXX}ok8|LT_Ѐ~ҥ?v*T0o? ^xiذ!%KyZ:BRdysB.ĢE R///ձ4Jbb"V¢"ؽ{1M&G}S~~}Uk׮4n܈'Nz GGGʕ+ˁشOE2mI!I0xpW.^Jٲhݺ5[Gu4:D6l:4ʕl,V9r  мy4߰+{%gϦT:3jTO_EUG@ Ld"l:W?UTm6?~\utȎ;U&͛7'\\ &.i@:U8p܉ ~Tbʕ+ROcܸq#FPHa~e&CtL2CCD*2$..8q"666l8]vPu4Ć Xl)ֶ ^Ru4ХK,Y-[קWуufBBBضm6ĉfӞܹI! .YOd͚={ѻwoիW']v&Wњ)wxκuشiWޢXt ;wf͚Oٿ?[xpArȎm֖ƍkfb(B@',,M~\xyMiޖ:дi 3R Ϯ]xyyKƵt }}Pwᱟmr}LLмy ZjE&M(V_,::s>M9)Qfff˗y7o^r̙5맜%))p"##yAAAxLPP>"669 (CJT<+ں| %= ƍ{ܸq['w< "W1̟?  SLLL011!W\-[6Ȓ ] x{tt4aaaBpp0l5kV)Ei,,PBi*V|tH! RMbb"O>'<|Ǐ#((pBB^uT먔A_?G=ƹ144335̄RPۯ*=Taa??G/ }IX+BC_k^$!!׼Ly}z-sG_?&&F'OnLL055DB+Vb RP>eUI !"BLL !"B@!ĤB!21)BL3 _IENDB`Text-RecordParser-1.6.5/bin/tab2graph000755 000765 000024 00000011355 12515523653 020227 0ustar00kyclarkstaff000000 000000 #!perl use strict; use warnings; use version; use English qw( -no_match_vars ); use File::Basename; use Getopt::Long; use GraphViz; use List::Util qw( max ); use Pod::Usage; use Readonly; use Scalar::Util qw( openhandle ); use Text::RecordParser; Readonly our $VERSION => 1.01; my $add_color = 0; my $fields = ''; my $fs = qq{\t}; my $is_directed = 0; my $layout = 'circo'; my $out_file = ''; my $out_format = 'png'; my $rs = qq{\n}; my $show_numbers = 0; my ( $help, $man_page, $show_version ); GetOptions( 'c|color' => \$add_color, 'd|directed' => \$is_directed, 'format:s' => \$out_format, 'fs:s' => \$fs, 'f|fields:s' => \$fields, 'help' => \$help, 'l|layout:s' => \$layout, 'man' => \$man_page, 'n|numbers' => \$show_numbers, 'o|out:s' => \$out_file, 'rs:s' => \$rs, 'version' => \$show_version, ) or pod2usage; if ( $help || $man_page ) { pod2usage({ -exitval => 0, -verbose => $man_page ? 2 : 1 }); }; if ( $show_version ) { my $prog = basename( $PROGRAM_NAME ); print "$prog $VERSION\n"; exit 0; } if ( !@ARGV ) { pod2usage('No input files'); } elsif ( @ARGV > 1 ) { pod2usage('Too many input files'); } my %field_filter = map { $_, 1 } split( /\s*,\s*/, $fields ); my $file = shift @ARGV; my $p = Text::RecordParser->new( filename => $file, field_separator => $fs, record_separator => $rs, trim => 1, ); my $g = GraphViz->new( directed => $is_directed, layout => $layout, bgcolor => $add_color ? 'lightgoldenrodyellow' : 'white', no_overlap => 1, node => { style => 'filled', fillcolor => 'white', } ); my @cols = $p->field_list; my %col_pos; for my $i ( 1..$#cols ) { # skip first col my $col_name = $cols[ $i ]; if ( %field_filter ) { next unless $field_filter{ $col_name }; } $g->add_node( $col_name ); $col_pos{ $i } = $col_name; } my $records = $p->fetchall_arrayref; my @edges; for my $data ( @$records ) { my $node_name = $data->[0]; $g->add_node( $node_name ); for my $i ( 1..$#cols ) { my $val = $data->[ $i ] or next; my $col = $col_pos{ $i } or next; if ( %field_filter ) { next unless defined $field_filter{ $col }; } if ( $val =~ /^\d+$/ && $val > 0 ) { push @edges, [ $cols[ $i ], $node_name, $val ]; } } } my $max_val = max( map { $_->[-1] } @edges ); for my $edge ( @edges ) { my $val = $edge->[-1]; my $weight = ( $val / $max_val ) * .5; $g->add_edge( $edge->[0], $edge->[1], $show_numbers ? ( label => $val ) : (), weight => $weight, ); } my $method = join '', 'as_', lc $out_format; if ( $out_file ) { open my $fh, '>', $out_file or die "Can't write '$out_file': $!\n"; binmode $fh; print $fh $g->$method; close $fh; my $basename = basename( $out_file ); print STDERR qq[Image created "$basename."\n]; } else { print $g->$method; } __END__ # ------------------------------------------------------------------- =pod =head1 NAME tab2graph - turn tabular data into a graph =head1 SYNOPSIS tab2graph [options] file.tab Options: -c|--color Add some color to the output (default is white) -d|--directed Make graph directed (default is not) -l|--layout GraphViz layout; choose from dot, neato, twopi, circo (default), and fdp -f|--fields Restrict to set of fields in first row -n|--numbers Show the numbers (default is not) -o|--out Name of output file (default is STDOUT) --format Output format (default is PNG) --fs=x Use "x" as the field separator (default is tab) --rs=x Use "x" as the record separator (default is newline) --help Show brief help and quit --man Show full documentation =head1 DESCRIPTION Turns tabular data into a graph using GraphViz. This may or may not be useful. =head1 SEE ALSO =over 4 =item * Text::RecordParser =item * GraphViz =back =head1 AUTHOR Ken Youens-Clark Ekclark@cpan.orgE. =head1 LICENSE AND COPYRIGHT Copyright (C) 2009-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut Text-RecordParser-1.6.5/bin/tablify000755 000765 000024 00000031264 12515524266 020011 0ustar00kyclarkstaff000000 000000 #!perl use strict; use warnings; use version; use File::Basename; use Getopt::Long; use List::Util 'max'; use Pod::Usage; use Readonly; use Text::Autoformat 'autoformat'; use Text::RecordParser; use Text::TabularDisplay; Readonly our $VERSION => 1.15; Readonly my $DASH => q{-}; Readonly my $EMPTY_STR => q{}; Readonly my $TAB => qq{\t}; Readonly my $NEWLINE => qq{\n}; Readonly my $WIDTH => 78; my $comment_start = ''; my $fs = $TAB; my $rs = $NEWLINE; my $headers = ''; my $no_headers = 0; my $show_vertically = 0; my $no_pager = 0; my $strip_quotes = 0; my ( $show_fields, $list, $limit, @where, $help, $man_page, $show_version ); GetOptions( 'c|comment:s' => \$comment_start, 'fs:s' => \$fs, 'rs:s' => \$rs, 'f|fields:s' => \$show_fields, 'l|list' => \$list, 'i|limit:i' => \$limit, 'w|where:s' => \@where, 'v|vertical' => \$show_vertically, 'strip-quotes' => \$strip_quotes, 'n|no-headers' => \$no_headers, 'h|headers:s' => \$headers, 'no-pager' => \$no_pager, 'help' => \$help, 'man' => \$man_page, 'version' => \$show_version, ) or pod2usage; if ( $help || $man_page ) { pod2usage({ -exitval => 0, -verbose => $man_page ? 2 : 1 }); }; if ( $show_version ) { my $prog = basename( $0 ); print "$prog $VERSION\n"; exit 0; } my $file = shift or pod2usage('No file'); my $p = Text::RecordParser->new( field_separator => $fs, record_separator => $rs, comment => $comment_start ? qr/^$comment_start/ : undef, ); if ( $strip_quotes ) { $p->field_filter( sub { s/^["']//; s/["']$//; $_ } ); } if ( $file eq $DASH ) { $p->fh( \*STDIN ); } else { $p->filename( $file ); } my @fields; if ( @fields = split( /\s*,\s*/, $headers ) ) { $p->bind_fields( @fields ); } elsif ( !$no_headers ) { $p->bind_header; @fields = $p->field_list; } if ( $list ) { pod2usage(q[Can't list fields with --no-headers]) if $no_headers; my $tab = Text::TabularDisplay->new('Field No.', 'Field'); my $i = 1; $tab->add( $i++, $_ ) for @fields; print $tab->render, $NEWLINE; exit 0; } my %where; for ( @where ) { if ( /([\w\d]+)\s*(==|eq|>=?|<=?|=~)\s*(.*)/ ) { my $field = $1; my $op = $2; my $value = $3; unless ( $no_headers ) { my %available = map { $_, 1 } @fields; next unless $available{ $field }; } $field-- if $field =~ /^\d+$/; $where{ $field } = [ $op, $value ]; } } if ( $show_fields ) { my @show = map { $_ =~ m/^\d+$/ && @fields ? $_-1 < scalar @fields ? $_ : () : $_ } map { $_ =~ m/(\d+)-(\d+)/ ? ( $1..$2 ) : $_ } split /,/, $show_fields; my @numbers = grep { /^(\d+)$/ } @show; if ( $no_headers ) { @fields = @show; } else { if ( scalar @show == scalar @numbers ) { # all numbers @numbers = map { $_ - 1 } @numbers; @fields = @fields[ @numbers ]; } elsif ( @show ) { my %available = map { $_, 1 } @fields; my @temp = @fields; @fields = map { $available{ $_ } ? $_ : () } @show; } if ( !@fields ) { die "No fields match in list '$show_fields'\n"; } } } my $fh; my $pager = $ENV{'PAGER'}; if ( !$no_pager && $pager ) { open $fh, "| $pager"; } else { $fh = \*STDOUT; } my $tab = Text::TabularDisplay->new( @fields ); my $max_col_length = 0; my $num_records = 0; my $separator = "************ Record %s ************\n"; if ( $no_headers ) { my @field_names; RECORD: while ( my @data = $p->fetchrow_array ) { if ( !@fields ) { @fields = ( 0..$#data ); @field_names = map { 'Field' . ($_+1) } @fields; $max_col_length = max( map { length $_ } @field_names ); $tab->columns( @field_names ); } for my $field ( keys %where ) { my ( $op, $value ) = @{ $where{ $field } }; my $cmd = "'$data[ ($field - 1) ]' $op $value"; next RECORD unless eval $cmd; } $num_records++; if ( $show_vertically ) { printf $fh $separator, $num_records; for my $i ( @fields ) { printf $fh "%${max_col_length}s: %s\n", $field_names[ $i ], defined $data[ $i ] ? $data[ $i ] : q{}; } } else { $tab->add( map { $data[ $_ ] } @fields ); } last if $limit && $num_records >= $limit; } } else { $max_col_length = max map { $_ ? length $_ : 0 } $p->field_list; RECORD: while ( my $data = $p->fetchrow_hashref ) { for my $field ( keys %where ) { my ( $op, $value ) = @{ $where{ $field } }; my $cmd = "'$data->{ $field }' $op $value"; next RECORD unless eval $cmd; } $num_records++; if ( $show_vertically ) { printf $fh $separator, $num_records; for my $field ( @fields ) { next unless $field; my $v = defined $data->{ $field } ? $data->{ $field } : q{}; if ( length $v > $WIDTH ) { ( $v = autoformat( $v, { left => $max_col_length + 3 } ) ) =~ s/^\s+|\s+$//g; } printf $fh "%${max_col_length}s: %s\n", $field, $v; } } else { $tab->add( map { $data->{ $_ } } @fields ); } last if $limit && $num_records >= $limit; } } if ( !$show_vertically ) { print $fh $tab->render; } print $fh $num_records ? sprintf( "\n%s record%s returned\n", $num_records, $num_records > 1 ? 's' : $EMPTY_STR ) : "\nNo records returned\n"; close $fh; __END__ # ------------------------------------------------------------------- # $Id: tablify,v 1.14 2006/03/07 17:20:00 kclark Exp $ =pod =head1 NAME tablify - turn a delimited text file into a text table =head1 SYNOPSIS tablify [options] file Options: -h|--help Show help -c|--comment Define the beginning of a (single-line) comment -n|--no-headers Assume first line is data, not headers --no-pager Do not use $ENV{'PAGER'} even if defined --strip-quotes Strip " or ' around fields -l|--list List the fields in the file (for use with -f) -f|--fields=f1[,f2] Show only fields in comma-separated list; when used in conjunction with "no-headers" the list should be field numbers (starting at 1); otherwise, should be field names -w|where=fv Apply the "cmp" Perl operator to restrict output where field "f" matches the value "v"; acceptable operators include ==, eq, >, >=, <=, and =~ -v|--vertical Show records vertically -i|--limit=n Limit to given number of records --fs=x Use "x" as the field separator (default is tab "\t") --rs=x Use "x" as the record separator (default is newline "\n") --as-html Create an HTML table instead of plain text --headers Comma-separated list of names matching the number of columns =head1 DESCRIPTION This script is essentially a quick way to parse a delimited text file and view it as a nice ASCII table. By selecting only certain B, employing a B clause to only select records where a field matches some value, and using the B to only see some of the output, you almost have a mini-database front-end for a simple text file. =head1 EXAMPLES Given a data file like this: name,rank,serial_no,is_living,age George,General,190293,0,64 Dwight,General,908348,0,75 Attila,Hun,,0,56 Tojo,Emporor,,0,87 Tommy,General,998110,1,54 To find the fields you can reference, use the B option: $ tablify --fs ',' -l people.dat +-----------+-----------+ | Field No. | Field | +-----------+-----------+ | 1 | name | | 2 | rank | | 3 | serial_no | | 4 | is_living | | 5 | age | +-----------+-----------+ To extract just the name and serial numbers, use the B option: $ tablify --fs ',' -f name,serial_no people.dat +--------+-----------+ | name | serial_no | +--------+-----------+ | George | 190293 | | Dwight | 908348 | | Attila | | | Tojo | | | Tommy | 998110 | +--------+-----------+ 5 records returned To extract the first through third fields and the fifth field (where field numbers start at "1" -- tip: use the B option to quickly determine field numbers), use this syntax for B: $ tablify --fs ',' -f 1-3,5 people.dat +--------+---------+-----------+------+ | name | rank | serial_no | age | +--------+---------+-----------+------+ | George | General | 190293 | 64 | | Dwight | General | 908348 | 75 | | Attila | Hun | | 56 | | Tojo | Emporor | | 87 | | Tommy | General | 998110 | 54 | +--------+---------+-----------+------+ 5 records returned To select only the ones with six serial numbers, use a B clause: $ tablify --fs ',' -w 'serial_no=~/^\d{6}$/' people.dat +--------+---------+-----------+-----------+------+ | name | rank | serial_no | is_living | age | +--------+---------+-----------+-----------+------+ | George | General | 190293 | 0 | 64 | | Dwight | General | 908348 | 0 | 75 | | Tommy | General | 998110 | 1 | 54 | +--------+---------+-----------+-----------+------+ 3 records returned To find Dwight's record, you would do this: $ tablify --fs ',' -w 'name eq "Dwight"' people.dat +--------+---------+-----------+-----------+------+ | name | rank | serial_no | is_living | age | +--------+---------+-----------+-----------+------+ | Dwight | General | 908348 | 0 | 75 | +--------+---------+-----------+-----------+------+ 1 record returned To find the name of all the people with a serial number who are living: $ tablify --fs ',' -f name -w 'is_living==1' -w 'serial_no>0' people.dat +-------+ | name | +-------+ | Tommy | +-------+ 1 record returned To filter outside of program and simply format the results, use "-" as the last argument to force reading of STDIN (and probably assume no headers): $ grep General people.dat | tablify --fs ',' -f 1-3 --no-headers - +---------+--------+--------+ | Field1 | Field2 | Field3 | +---------+--------+--------+ | General | 190293 | 0 | | General | 908348 | 0 | | General | 998110 | 1 | +---------+--------+--------+ 3 records returned When dealing with data lacking field names, you can specify "no-headers" and then refer to fields by number (starting at one), e.g.: $ tail -5 people.dat | tablify --fs ',' --no-headers -w '3 eq "General"' - +--------+---------+--------+--------+--------+ | Field1 | Field2 | Field3 | Field4 | Field5 | +--------+---------+--------+--------+--------+ | George | General | 190293 | 0 | 64 | | Dwight | General | 908348 | 0 | 75 | | Tommy | General | 998110 | 1 | 54 | +--------+---------+--------+--------+--------+ 3 records returned If your file has many fields which are hard to see across the screen, consider using the vertical display with "-v" or "--vertical", e.g.: $ tablify --fs ',' -v --limit 1 people.dat ************ Record 1 ************ name: George rank: General serial_no: 190293 is_living: 0 age : 64 1 record returned =head1 SEE ALSO =over 4 =item * Text::RecordParser =item * Text::TabularDisplay =item * DBD::CSV Although I don't DBD::CSV this module, the idea was much the inspiration for this. I just didn't want to have to install DBI and DBD::CSV to get this kind of functionality. I think my interface is simpler. =back =head1 AUTHOR Ken Youens-Clark Ekclark@cpan.orgE. =head1 LICENSE AND COPYRIGHT Copyright (C) 2006-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut Text-RecordParser-1.6.5/bin/tabmerge000755 000765 000024 00000023542 12515523661 020143 0ustar00kyclarkstaff000000 000000 #!perl use strict; use warnings; use version; use English qw( -no_match_vars ); use File::Basename; use Getopt::Long; use Pod::Usage; use Readonly; use Text::RecordParser; use Text::TabularDisplay; Readonly our $VERSION => 1.12; Readonly my $COMMA => q{,}; Readonly my $COMMA_SPACE => q{, }; Readonly my $DASH => q{-}; Readonly my $EMPTY_STR => q{}; Readonly my $TAB => qq{\t}; Readonly my $NEWLINE => qq{\n}; my $fs = $TAB; my $rs = $NEWLINE; my ( $fields, $min, $max, $list, $sort, $stdout, $help, $man_page, $show_version ); GetOptions( 'f|fields:s' => \$fields, 'help' => \$help, 'fs:s' => \$fs, 'l|list' => \$list, 'man' => \$man_page, 'min' => \$min, 'max' => \$max, 'rs:s' => \$rs, 's|sort:s' => \$sort, 'stdout' => \$stdout, 'version' => \$show_version, ) or pod2usage; if ( $help || $man_page ) { pod2usage({ -exitval => 0, -verbose => $man_page ? 2 : 1 }); }; if ( $show_version ) { my $prog = basename( $PROGRAM_NAME ); print "$prog $VERSION\n"; exit 0; } if ( scalar @ARGV < 2 ) { pod2usage('Please supply two or more files'); } my @files = @ARGV or pod2usage('No input files'); $min = 1 unless $max or $fields; my $p = Text::RecordParser->new( field_separator => $fs, record_separator => $rs, ); if ( $list ) { list( $p, @files ); } elsif ( $min || $max || $fields ) { intersection( fields => $fields, files => \@files, parser => $p, sort => $sort, type => $min ? 'min' : 'max', ); } else { pod2usage(q[Can't figure out what to do.]); } # ------------------------------------------------------------------- sub intersection { my %args = @_; my $p = $args{'parser'}; my $type = $args{'type'}; my $files = $args{'files'}; my $fields = $args{'fields'} || $EMPTY_STR; # optional my $sort = $args{'sort'} || $EMPTY_STR; # optional my %fields; for my $file ( @$files ) { $p->filename( $file ); $p->bind_header; $fields{ $_ }++ for $p->field_list; } my @intersect; if ( $fields ) { @intersect = map { s/^\s+|\s+$//g; $_ } split /$COMMA/, $fields; die_if_bad( \%fields, \@intersect ); } else { my $no_files = scalar @$files; for my $fld ( keys %fields ) { push @intersect, $fld if ( $type eq 'max' ) || ( $type eq 'min' && $fields{ $fld } == $no_files ) ; } @intersect = sort @intersect; } die "No intersection!\n" unless @intersect; my @data; for my $file ( @$files ) { $p->filename( $file ); $p->bind_header; while ( my $rec = $p->fetchrow_hashref ) { push @data, { map { $_, $rec->{ $_ } } @intersect }; } } if ( my @sort = map { s/^\s+|\s+$//g; $_ } split /$COMMA/, $sort ) { die_if_bad( \%fields, \@sort ); @data = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [ join($DASH, @{ $_ }{ @sort } ), $_ ] } @data; } if ( $stdout ) { print join( $fs, @intersect ), $rs; for my $rec ( @data ) { print join( $fs, map { defined $rec->{$_} ? $rec->{$_} : $EMPTY_STR } @intersect ), $rs; } } else { my $tab = Text::TabularDisplay->new( @intersect ); for my $rec ( @data ) { $tab->add( map { $rec->{ $_ } } @intersect ); } print $tab->render, $NEWLINE; } } # ------------------------------------------------------------------- sub list { my ( $p, @files ) = @_; my %fields; for my $file ( @files ) { $p->filename( $file ); $p->bind_header; $fields{ $_ }++ for $p->field_list; } my $tab = Text::TabularDisplay->new('Field', 'No. Times Present'); $tab->add( $_, $fields{ $_ } ) for sort keys %fields; print $tab->render, $NEWLINE; } # ------------------------------------------------------------------- sub die_if_bad { my ( $fields, $check ) = @_; my @bad; for my $fld ( @$check ) { push @bad, $fld unless $fields->{ $fld }; } if ( @bad ) { die sprintf "Bad field name%s: %s$NEWLINE", scalar @bad > 1 ? 's' : $EMPTY_STR, join $COMMA_SPACE, @bad ; } else { return 1; } } __END__ # ------------------------------------------------------------------- # $Id: tabmerge,v 1.11 2006/03/07 17:20:00 kclark Exp $ =pod =head1 NAME tabmerge - unify delimited files on common fields =head1 SYNOPSIS tabmerge [action] [options] file1 file2 [...] Actions: --min Take only fields present in all files [DEFAULT] --max Take all fields present -f|--fields=f1[,f2] Take only the fields mentioned in the comma-separated list Options: -l|--list List available fields --fs=x Use "x" as the field separator (default is tab "\t") --rs=x Use "x" as the record separator (default is newline "\n") -s|--sort=f1[,f2] Sort data ASCII-betically on field(s) --stdout Print data in original delimited format (i.e., not in a table format) --help Show brief help and quit --man Show full documentation =head1 DESCRIPTION This program merges the fields -- not the rows -- of delimited text files. That is, if several files are almost but not quite entirely unlike each other in their structure (in their field names, numbers or orders), this script allows you to easily unify the files into one file with all the same fields. The output can be based on fields as determined by the three "action" flags. For the following examples, consider three files that contain the following fields: +------------+---------------------------------+ | File | Fields | +------------+---------------------------------+ | merge1.tab | name, type, position | | merge2.tab | name, type, position, lod_score | | merge3.tab | name, position | +------------+---------------------------------+ To list all available fields in the files and the number of times they are present: $ tabmerge --list merge* +-----------+-------------------+ | Field | No. Times Present | +-----------+-------------------+ | lod_score | 1 | | name | 3 | | position | 3 | | type | 2 | +-----------+-------------------+ To merge the files on the minimum overlapping fields: $ tabmerge merge* +----------+----------+ | name | position | +----------+----------+ | RM104 | 2.30 | | RM105 | 4.5 | | TX5509 | 10.4 | | UU189 | 19.0 | | Xpsm122 | 3.3 | | Xpsr9556 | 4.5 | | DRTL | 2.30 | | ALTX | 4.5 | | DWRF | 10.4 | +----------+----------+ To merge the files and include all the fields: $ tabmerge --max merge* +-----------+----------+----------+--------+ | lod_score | name | position | type | +-----------+----------+----------+--------+ | | RM104 | 2.30 | RFLP | | | RM105 | 4.5 | RFLP | | | TX5509 | 10.4 | AFLP | | 2.4 | UU189 | 19.0 | SSR | | 1.2 | Xpsm122 | 3.3 | Marker | | 1.2 | Xpsr9556 | 4.5 | Marker | | | DRTL | 2.30 | | | | ALTX | 4.5 | | | | DWRF | 10.4 | | +-----------+----------+----------+--------+ To merge and extract just the "name" and "type" fields: $ tabmerge -f name,type merge* +----------+--------+ | name | type | +----------+--------+ | RM104 | RFLP | | RM105 | RFLP | | TX5509 | AFLP | | UU189 | SSR | | Xpsm122 | Marker | | Xpsr9556 | Marker | | DRTL | | | ALTX | | | DWRF | | +----------+--------+ To merge the files on just the "name" and "lod_score" fields and sort on the name: $ tabmerge -f name,lod_score -s name merge* +----------+-----------+ | name | lod_score | +----------+-----------+ | ALTX | | | DRTL | | | DWRF | | | RM104 | | | RM105 | | | TX5509 | | | UU189 | 2.4 | | Xpsm122 | 1.2 | | Xpsr9556 | 1.2 | +----------+-----------+ To do the same but mimic the original tab-delimited input: $ tabmerge -f name,lod_score -s name --stdout merge* name lod_score ALTX DRTL DWRF RM104 RM105 TX5509 UU189 2.4 Xpsm122 1.2 Xpsr9556 1.2 Why would you want to do this? Suppose you have several delimited text files with nearly the same structure and want to create just one file from them, but the fields may be in a different order in each file and/or some files may contain more or fewer fields than others. (As far-fetched as it may seem, it happens to the author more than he'd like.) =head1 SEE ALSO =over 4 =item * Text::RecordParser =item * Text::TabularDisplay =back =head1 AUTHOR Ken Youens-Clark Ekclark@cpan.orgE. =head1 LICENSE AND COPYRIGHT Copyright (C) 2006-10 Ken Youens-Clark. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. =cut