Log-Shiras
view release on metacpan or search on metacpan
lib/Log/Shiras/Report/CSVFile.pm view on Meta::CPAN
sub _scrub_header_string{
my ( $self, $string ) = @_;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 2,
###InternalReporTCSV name_space => $self->get_all_space( '_scrub_header_string' ),
###InternalReporTCSV message =>[ "Arrived at _scrub_header_string with: $string" ], } );
$string = lc( $string );
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 0,
###InternalReporTCSV name_space => $self->get_all_space( '_scrub_header_string' ),
###InternalReporTCSV message =>[ "The updated string is: $string" ], } );
$string =~ s/\n/ /gsxm;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 0,
###InternalReporTCSV name_space => $self->get_all_space( '_scrub_header_string' ),
###InternalReporTCSV message =>[ "The updated string is: $string" ], } );
$string =~ s/\r/ /gsxm;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 0,
###InternalReporTCSV name_space => $self->get_all_space( '_scrub_header_string' ),
###InternalReporTCSV message =>[ "The updated string is: $string" ], } );
$string =~ s/\s/_/gsxm;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 0,
###InternalReporTCSV name_space => $self->get_all_space( '_scrub_header_string' ),
###InternalReporTCSV message =>[ "The updated string is: $string" ], } );
chomp $string;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 2,
###InternalReporTCSV name_space => $self->get_all_space( '_scrub_header_string' ),
###InternalReporTCSV message =>[ "The final string is: $string" ], } );
return $string;
}
sub DEMOLISH{
my ( $self ) = @_;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 2,
###InternalReporTCSV name_space => $self->get_all_space( 'DEMOLISH' ),
###InternalReporTCSV message =>[ "Arrived at DEMOLISH" ], } ) if $switchboard;
if( $self->_has_file_handle ){
flock( $self->_get_file_handle, LOCK_UN );
close( $self->_get_file_handle ) or confess "Couldn't close the file handle";
$self->_clear_file_handle;
###InternalReporTCSV $switchboard->master_talk( { report => 'log_file', level => 1,
###InternalReporTCSV name_space => $self->get_all_space( 'DEMOLISH' ),
###InternalReporTCSV message =>[ "Arrived at DEMOLISH" ], } ) if $switchboard;
}
}
#########1 Phinish 3#########4#########5#########6#########7#########8#########9
__PACKAGE__->meta->make_immutable;
1;
# The preceding line will help the module return a true value
#########1 main pod docs 3#########4#########5#########6#########7#########8#########9
__END__
=head1 NAME
Log::Shiras::Report::CSVFile - A report base for csv files
=head1 SYNOPSIS
use Modern::Perl;
#~ use Log::Shiras::Unhide qw( :InternalReporTCSV );
use Log::Shiras::Switchboard;
use Log::Shiras::Telephone;
use Log::Shiras::Report;
use Log::Shiras::Report::CSVFile;
use Log::Shiras::Report::Stdout;
$ENV{hide_warn} = 1;
$| = 1;
my $operator = Log::Shiras::Switchboard->get_operator(
name_space_bounds =>{
UNBLOCK =>{
to_file => 'info',# for info and more urgent messages
},
},
reports =>{
to_file =>[{
superclasses =>[ 'Log::Shiras::Report::CSVFile' ],
roles =>[ 'Log::Shiras::Report' ],# checks inputs and class requirements
file => 'test.csv',
}],
}
);
my $telephone = Log::Shiras::Telephone->new( report => 'to_file' );
$telephone->talk( level => 'info', message => 'A new line' );
$telephone->talk( level => 'trace', message => 'A second line' );
$telephone->talk( level => 'warn', message =>[ {
header_0 => 'A third line',
new_header => 'new header starts here' } ] );
#######################################################################################
# Synopsis file (test.csv) output
# 01: header_0
# 02: "A new line"
# 03: "A third line"
#######################################################################################
#######################################################################################
# Synopsis file (test.csv) output with line 24 commented out
# 01: header_0,new_header
# 02: "A third line","new header starts here"
#######################################################################################
=head1 DESCRIPTION
This is a report module that can act as a destination in the
L<Log::Shiras::Switchboard/reports> name-space. It is meant to be fairly flexible and
will have most of the needed elements in the class without added roles. An instance
of the class can be built either with ->new or using the implied
L<MooseX::ShortCut::BuildInstance> helpers. (See lines 18 - 20 in the example) When the
report is set up any call to that report namespace will then implement the L<add_line
|/add_line> method of this class.
As implied in the Synopsis one of the features of this class is the fact that it will try to
reconcile the headers to inbound data and header requests. This class will attempt to
reconcile any deviation between the first passed row and the header. Subsequent added
rows using a passed array ref will add all values without warning whether the count matches
the header count or not. Subsequent added rows using a passed hashref will only used the
headers in the fixed L<header|/header> list but will warn for any passed headers not matching
the header list.
( run in 1.207 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )