| 1 | #!/usr/bin/perl | ||||||||||||
| 2 | ## Emacs: -*- tab-width: 4; -*- | ||||||||||||
| 3 | |||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | package Data::CTable::ProgressLogger; | ||||||||||||
| 7 | |||||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION); $VERSION = '0.1'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | =pod | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 NAME | ||||||||||||
| 13 | |||||||||||||
| 14 | Data::CTable::ProgressLogger - CTable that stores messages in the object | ||||||||||||
| 15 | |||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||
| 17 | |||||||||||||
| 18 | my $Table = Data::CTable::ProgressLogger->new("mydata.txt"); | ||||||||||||
| 19 | # ... do stuff... | ||||||||||||
| 20 | $Table->write(); | ||||||||||||
| 21 | $Table->show_log(); | ||||||||||||
| 22 | |||||||||||||
| 23 | =head1 OVERVIEW | ||||||||||||
| 24 | |||||||||||||
| 25 | ProgressLogger is a subclass of Data::CTable. | ||||||||||||
| 26 | |||||||||||||
| 27 | The only difference is that it enables per-instance progress by | ||||||||||||
| 28 | defaul, but it stores progress messages in the object instead of | ||||||||||||
| 29 | sending them to STDERR. | ||||||||||||
| 30 | |||||||||||||
| 31 | Later, they can be gotten in an array by calling the log() method | ||||||||||||
| 32 | or dumped with show_log(). | ||||||||||||
| 33 | |||||||||||||
| 34 | =cut | ||||||||||||
| 35 | |||||||||||||
| 36 | 1 | ▶ | use Data::CTable; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 1 | ▶ | use vars qw(@ISA); @ISA=qw(Data::CTable); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | |||||||||||||
| 39 | sub initialize ## Add a new param; change one default | ||||||||||||
| 40 | 1 | ▶ | { | ||||||||||
|
Subroutine
initialize: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||
| 41 | 1 | my $this = shift; | |||||||||||
| 42 | 1 | ▶ | $this->{_Progress} = 1 unless exists($this->{_Progress}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 1 | ▶ | $this->{_ProgrLog} ||= []; | ||||||||||
|
Condition50%1/2
$this->{"_ProgrLog"} ||= []
MC/DC0%0/1
$this->{"_ProgrLog"} ||= []
$this->{"_ProgrLog"}
Truth table50%1/2
A
A= $this->{"_ProgrLog"}
| |||||||||||||
| 44 | 1 | $this->SUPER::initialize(); | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | sub progress_default ## Log message to object's ProgMsgs list | ||||||||||||
| 48 | 2 | ▶ | { | ||||||||||
|
Subroutine
progress_default: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 49 | 2 | my $this = shift; | |||||||||||
| 50 | 2 | my ($msg) = @_; | |||||||||||
| 51 | 2 | chomp $msg; | |||||||||||
| 52 | 2 | push @{$this->{_ProgrLog}}, localtime() . " $msg"; | |||||||||||
| 53 | |||||||||||||
| 54 | 2 | return(1); | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | sub log | ||||||||||||
| 58 | 1 | ▶ | { | ||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 59 | 1 | my $this = shift; | |||||||||||
| 60 | |||||||||||||
| 61 | 1 | return($this->{_ProgrLog}); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | sub show_log ## Use Dumper to spit out the log list | ||||||||||||
| 65 | 0 | ▶ | { | ||||||||||
|
Subroutine
show_log: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 66 | 0 | my $this = shift; | |||||||||||
| 67 | 0 | $this->dump($this->log()); | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 1 | 1; | |||||||||||