File Coverage

blib/lib/Data/iRealPro/Output.pm
Criterion Covered Total %
statement 18 47 38.3
branch 0 14 0.0
condition 0 14 0.0
subroutine 6 8 75.0
pod 0 2 0.0
total 24 85 28.2


line stmt bran cond sub pod time code
1             #! perl
2              
3             # Data::iRealPro::Output -- pass data to backends
4              
5             # Author : Johan Vromans
6             # Created On : Tue Sep 6 16:09:10 2016
7             # Last Modified By: Johan Vromans
8             # Last Modified On: Thu Nov 1 21:08:33 2018
9             # Update Count : 79
10             # Status : Unknown, Use with caution!
11              
12             ################ Common stuff ################
13              
14 1     1   885 use strict;
  1         2  
  1         29  
15 1     1   5 use warnings;
  1         2  
  1         23  
16 1     1   4 use Carp;
  1         4  
  1         42  
17 1     1   6 use utf8;
  1         1  
  1         5  
18              
19             package Data::iRealPro::Output;
20              
21 1     1   30 use Data::iRealPro::Input;
  1         2  
  1         33  
22 1     1   6 use Encode qw ( decode_utf8 );
  1         2  
  1         464  
23              
24             sub new {
25 0     0 0   my ( $pkg, $options ) = @_;
26              
27 0           my $self = bless( { variant => "irealpro" }, $pkg );
28 0           my $opts;
29              
30 0   0       $opts->{output} = $options->{output} || "";
31 0   0       $opts->{transpose} = $options->{transpose} // 0;
32 0 0         if ( $options->{generate} ) {
33 0           $self->{_backend} = "Data::iRealPro::Output::" . ucfirst($options->{generate});
34 0           eval "require $self->{_backend}";
35 0 0         die($@) if $@;
36 0   0       $opts->{output} ||= "-";
37             }
38              
39 0 0 0       if ( $options->{list}
    0 0        
    0          
    0          
40             || $opts->{output} =~ /\.txt$/i ) {
41 0           require Data::iRealPro::Output::Text;
42 0           $self->{_backend} = Data::iRealPro::Output::Text::;
43 0   0       $opts->{output} ||= "-";
44             }
45             elsif ( $opts->{output} =~ /\.jso?n$/i ) {
46 0           require Data::iRealPro::Output::JSON;
47 0           $self->{_backend} = Data::iRealPro::Output::JSON::;
48             }
49             elsif ( $options->{split}
50             || $opts->{output} =~ /\.html$/i ) {
51 0           require Data::iRealPro::Output::HTML;
52 0           $self->{_backend} = Data::iRealPro::Output::HTML::;
53             }
54             elsif ( !$self->{_backend} ) {
55 0           require Data::iRealPro::Output::Imager;
56 0           $self->{_backend} = Data::iRealPro::Output::Imager::;
57             }
58              
59 0           for ( @{ $self->{_backend}->options } ) {
  0            
60 0 0         $opts->{$_} = $options->{$_} if exists $options->{$_};
61             }
62              
63 0           $self->{options} = $opts;
64 0           return $self;
65             }
66              
67             sub processfiles {
68 0     0 0   my ( $self, @files ) = @_;
69 0           my $opts = $self->{options};
70              
71 0           my $all = Data::iRealPro::Input->new($opts)->parsefiles(@files);
72 0           $self->{_backend}->new($opts)->process( $all, $opts );
73             }
74              
75             1;