File Coverage

blib/lib/oEdtk/Doc.pm
Criterion Covered Total %
statement 9 55 16.3
branch 0 12 0.0
condition 0 3 0.0
subroutine 3 12 25.0
pod 0 9 0.0
total 12 91 13.1


line stmt bran cond sub pod time code
1             package oEdtk::Doc;
2             our $VERSION = '0.05';
3              
4 1     1   8 use Scalar::Util qw(blessed);
  1         1  
  1         99  
5 1     1   6 use overload '""' => \&dump;
  1         2  
  1         13  
6 1     1   342 use oEdtk::Config (config_read);
  1         2  
  1         697  
7             # The maximum number of characters to output before inserting
8             # a newline character.
9             my $LINE_CUTOFF = 120;
10              
11              
12             sub new {
13 0     0 0   my ($class) = @_;
14              
15 0           my $self = {};
16 0           bless $self, $class;
17 0           $self->reset();
18 0           return $self;
19             }
20              
21              
22             sub reset {
23 0     0 0   my ($self) = @_;
24              
25 0           $self->{'taglist'} = [];
26 0           $self->{'emitted'} = 0;
27             }
28              
29              
30             sub append {
31 0     0 0   my ($self, $name, $value) = @_;
32              
33 0 0 0       if (blessed($name) && $name->isa('oEdtk::Doc')) {
    0          
34 0           push(@{$self->{'taglist'}}, @{$name->{'taglist'}});
  0            
  0            
35             } elsif (ref($name) eq 'HASH') {
36 0           while (my ($key, $val) = each(%$name)) {
37 0           $self->append($key, $val);
38             }
39             } else {
40 0           my $tag = $self->mktag($name, $value);
41 0           push(@{$self->{'taglist'}}, $tag);
  0            
42             }
43             }
44              
45              
46             sub dump {
47 0     0 0   my ($self) = @_;
48              
49 0           my $out = '';
50 0           foreach (@{$self->{'taglist'}}) {
  0            
51 0           my $tag = $_->emit;
52 0           my $taglen = length $tag;
53 0 0         if ($self->{'emitted'} + $taglen > $LINE_CUTOFF) {
54 0           $out .= $self->line_break();
55 0           $self->{'emitted'} = 0;
56             }
57 0           $self->{'emitted'} += $taglen;
58 0           $out .= $tag;
59             }
60 0           return $out;
61             }
62              
63              
64             sub include {
65 0     0 0   my ($self, $file, $path) = @_;
66              
67 0 0         if (defined $path){
68 0 0         if ($path=~/^EDTK_DIR_/) {
69 0           my $cfg = config_read('ENVDESC');
70 0           $path = $cfg->{$path};
71             }
72             } else {
73 0           $path = ".";
74 0           warn "INFO : include param1 is $file, assuming param2 is $path \n";
75             }
76              
77 0           my $link = $path ."/". $file;
78 0           $link=~s/\\/\//g;
79 0 0         if (-e $link){} else {die "ERROR: can't find include $link\n";}
  0            
80              
81 0           $self->append("_include_", $link);
82             }
83              
84              
85             # THE FOLLOWINGS METHODS SHOULD ONLY BE IMPLEMENTED BY
86             # THE SUBCLASSES (SEE C7DOC OR TEXDOC).
87             sub mktag {
88 0     0 0   die "ERROR: oEdtk::Doc::mktag unimplemented method\n";
89             }
90              
91              
92             sub append_table {
93 0     0 0   die "ERROR: oEdtk::Doc::append_table unimplemented method\n";
94             }
95              
96              
97             sub line_break {
98 0     0 0   die "ERROR: oEdtk::Doc::line_break unimplemented method\n";
99             }
100              
101              
102             sub escape {
103 0     0 0   die "ERROR: oEdtk::Doc::escape unimplemented method\n";
104             }
105              
106             1;