LRpt

 view release on metacpan or  search on metacpan

lib/LRpt/CSVDiff.pm  view on Meta::CPAN


#
# Switch deciding what to print on the difference report. 
#
our $print_all = "";

=head1 METHODS

In this sections you will find a more or less complete listing of all
methods provided by the package. 

=cut

############################################################################

=head2 C<diff>

  diff( @ARGV );

Main function. @ARGV is processed by standard Getopt::Long module.
Switches have the following meaning (see L<SYNOPSIS|"SYNOPSIS">.

=over 4

=item --all

If set, not only differences are reported, but all rows from both rowsets.

=item --key=string

Row key defined in command line as one string. Don't use it. I will probably
get read of this switch in future

=item --keys_file=file

Name of the file containing row keys definitions

=item --chunk_size=num

Number of rows retrieved in one chunk. If not defined - default chunking size
is used. If equal to zero, than no chunking is used (all rows are loaded
to memory

=item before_dir

A file name or a directory containing files with I<before> state.

=item after_dir

A file name of a directory containing files with I<after> state.

=back

=cut

##########################################################################
sub diff
{
    my ( $ext, $path, $sep, $chunk_size, $keys_file, $global_keys );
    my $skip_cols_file;
    local ( @ARGV ) = @_;
    my $help = "";
    my @key      = ();
    my @key_cols = ();
    my $skip_cols_string;

    GetOptions( "ext=s"       => \$ext,
                "path=s"      => \$path,
                "sep=s"       => \$sep,
                "key=s"      => \@key,
                "key_cols=s"  => \@key_cols,
                "keys_file=s" => \$keys_file,
                "skip_cols=s"  => \$skip_cols_string,
                "skip_cols_file=s"  => \$skip_cols_file,
                "all" =>          \$print_all,
                "global_keys" =>  \$global_keys,
                "chunk_size=s" => \$chunk_size,
                "help" =>         \$help );

    if( $print_all ){
        $print_all = 'all';
    }

    if( $help ){
        print_usage();
    }

    my $config = LRpt::Config->new( 'ext'       => $ext,
                                    'path'      => $path,
                                    'sep'       => $sep,
                                    'chunk_size' => $chunk_size );

    $rkeys_rdr = LRpt::RKeysRdr->new( 'fname'    => $keys_file,
                                      'key'      => \@key,
                                      'key_cols' => \@key_cols,
                                      'global_keys' => $global_keys );

    parse_skip_cols( $skip_cols_string, $skip_cols_file ); 
    my $file1 = shift( @ARGV );
    my $file2 = shift( @ARGV );

    compare( $file1, $file2 );
}

sub parse_skip_cols
{
    my $skip_cols_string = shift;
    my $skip_cols_file   = shift;

    $skip_cols{ 'default' } = {};
    my @skip_strings = ();
    if( $skip_cols_string ){
        @skip_strings = split( /,/, $skip_cols_string );
        my $def_ref = $skip_cols{ 'default' };
        @$def_ref{ @skip_strings } = 1;
    }

    if( $skip_cols_file ){
        my @skip_cols_rules = ( { 'name' => 'select_name' },
                                { 'name' => 'columns' } );
        open( SKIPS, "<$skip_cols_file" ) or 



( run in 1.139 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )