| 1 | # This class represents an possible output format for analizo operations. It | ||||||||||
| 2 | # has the responsibility to generate an output based on a series of jobs, and to inform | ||||||||||
| 3 | # | ||||||||||
| 4 | package Analizo::Batch::Output; | ||||||||||
| 5 | |||||||||||
| 6 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 14 | ▶ | use parent qw(Class::Accessor::Fast); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 10 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 12 | 10 | my ($class) = @_; | |||||||||
| 13 | 10 | return bless {}, $class; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | # This method must be overriden by subclasses, and must return 0 or 1 based on | ||||||||||
| 17 | # whether the given output format requires calculation of metrics or not. | ||||||||||
| 18 | # | ||||||||||
| 19 | # Given that calculating metrics requires a significant amount of processing, | ||||||||||
| 20 | # by default we return 0 here. | ||||||||||
| 21 | 1 | ▶ | sub requires_metrics { | ||||||||
|
Subroutine
requires_metrics: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 22 | 1 | 0; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | # Runners must use this method to push jobs into the output object. | ||||||||||
| 26 | # | ||||||||||
| 27 | # Subclasses (output drives) must override this method. Output drives MAY NOT | ||||||||||
| 28 | # ASSUME that the jobs will be pushed in any particular order. | ||||||||||
| 29 | 0 | ▶ | sub push { | ||||||||
|
Subroutine
push: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | # To which file the output must be written | ||||||||||
| 33 | 14 | __PACKAGE__->mk_accessors(qw(file)); | |||||||||
| 34 | |||||||||||
| 35 | # Makes any initialization needed for the given output driver. | ||||||||||
| 36 | # | ||||||||||
| 37 | # This method must be overriden by subclasses | ||||||||||
| 38 | 2 | ▶ | sub initialize { | ||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # Opens a file for output, delegates the actual writing to subclasses, and | ||||||||||
| 42 | # closes the file. If no file was given, write to standard output. | ||||||||||
| 43 | 3 | ▶ | sub flush { | ||||||||
|
Subroutine
flush: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 44 | 3 | my ($self) = @_; | |||||||||
| 45 | 3 | ▶ | if ($self->file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 1 | ▶ | open(my $fh, '>', $self->file) or die("Could not open output file $self->file: $!"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | $self->write_data($fh); | |||||||||
| 48 | 1 | close($fh); | |||||||||
| 49 | } else { | ||||||||||
| 50 | 2 | $self->write_data(*STDOUT); | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | # Must be overriden by subclasses. Will receive a FILEHANDLE, and must write | ||||||||||
| 55 | # the data to it. | ||||||||||
| 56 | 1 | ▶ | sub write_data { | ||||||||
|
Subroutine
write_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 14 | 1; | |||||||||