Mercurial > repos > cpt > cpt_psm_recombine
comparison lib/CPT/Report/HTML.pm @ 1:97ef96676b48 draft
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
author | cpt |
---|---|
date | Mon, 05 Jun 2023 02:51:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:b18e8268bf4e | 1:97ef96676b48 |
---|---|
1 package CPT::Report::HTML; | |
2 no warnings; | |
3 use Moose; | |
4 use Carp; | |
5 with 'CPT::Report'; | |
6 use CGI; | |
7 | |
8 has cgi => ( | |
9 is => 'rw', | |
10 isa => 'Any', | |
11 default => sub { | |
12 CGI->new(); | |
13 }, | |
14 # other attributes | |
15 ); | |
16 | |
17 sub header { | |
18 my ($self) = @_; | |
19 return $self->cgi()->start_html( | |
20 -style => { -src => ['http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css','http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css'] } | |
21 ); | |
22 } | |
23 | |
24 sub footer{ | |
25 my ($self) = @_; | |
26 return $self->cgi()->end_html(); | |
27 } | |
28 sub h1{ | |
29 my ($self, $addition) = @_; | |
30 $self->a($self->cgi()->h1($addition)); | |
31 } | |
32 sub h2{ | |
33 my ($self, $addition) = @_; | |
34 $self->a($self->cgi()->h2($addition)); | |
35 } | |
36 sub h3{ | |
37 my ($self, $addition) = @_; | |
38 $self->a($self->cgi()->h3($addition)); | |
39 } | |
40 sub h4{ | |
41 my ($self, $addition) = @_; | |
42 $self->a($self->cgi()->h4($addition)); | |
43 } | |
44 sub h5{ | |
45 my ($self, $addition) = @_; | |
46 $self->a($self->cgi()->h5($addition)); | |
47 } | |
48 sub h6{ | |
49 my ($self, $addition) = @_; | |
50 $self->a($self->cgi()->h6($addition)); | |
51 } | |
52 sub p{ | |
53 my ($self, $addition) = @_; | |
54 $self->a($self->cgi()->p($addition)); | |
55 } | |
56 sub b{ | |
57 my ($self, $addition) = @_; | |
58 $self->a($self->cgi()->b($addition)); | |
59 } | |
60 | |
61 sub finalize_table{ | |
62 my ($self) = @_; | |
63 my @td; | |
64 if(defined $self->_table_header() && scalar @{$self->_table_header()} > 0 ){ | |
65 push(@td, $self->cgi->th($self->_table_header())); | |
66 } | |
67 foreach(@{$self->_table_data()}){ | |
68 push(@td, $self->cgi->td($_)); | |
69 } | |
70 | |
71 $self->a($self->cgi()->table( | |
72 {-class => "table table-striped"}, | |
73 $self->cgi->Tr(\@td) | |
74 ) | |
75 ); | |
76 | |
77 # Reset for next usage | |
78 $self->_table_header([]); | |
79 $self->_table_data([]); | |
80 } | |
81 | |
82 has _table_header => ( | |
83 is => 'rw', | |
84 isa => 'ArrayRef', | |
85 ); | |
86 has _table_data => ( | |
87 is => 'rw', | |
88 isa => 'ArrayRef', | |
89 default => sub { [] }, | |
90 ); | |
91 | |
92 | |
93 sub table_header { | |
94 my ($self, @values) = @_; | |
95 $self->_table_header(\@values); | |
96 } | |
97 | |
98 sub table_row { | |
99 my ($self, @values) = @_; | |
100 my @current = @{$self->_table_data()}; | |
101 push(@current, \@values); | |
102 $self->_table_data(\@current); | |
103 } | |
104 | |
105 sub list_start { | |
106 my ($self, $type) = @_; | |
107 if($type ne 'number' && $type ne 'bullet'){ | |
108 carp 'Must use number or bullet as list type'; | |
109 } | |
110 if($self->_list_type() eq 'number'){ | |
111 $self->a('<ol>'); | |
112 }else{ | |
113 $self->a('<ul>'); | |
114 } | |
115 $self->_list_type($type); | |
116 } | |
117 | |
118 sub list_end { | |
119 my ($self) = @_; | |
120 if($self->_list_type() eq 'number'){ | |
121 $self->a('</ol>'); | |
122 }else{ | |
123 $self->a('</ul>'); | |
124 } | |
125 } | |
126 | |
127 sub list_element { | |
128 my ($self, $element_text) = @_; | |
129 $element_text =~ s{&}{&}gso; | |
130 $element_text =~ s{<}{<}gso; | |
131 $element_text =~ s{>}{>}gso; | |
132 $element_text =~ s{"}{"}gso; | |
133 $self->a(sprintf('<li>%s</li>', $element_text)); | |
134 } | |
135 | |
136 no Moose; | |
137 1; | |
138 | |
139 __END__ | |
140 | |
141 =pod | |
142 | |
143 =encoding UTF-8 | |
144 | |
145 =head1 NAME | |
146 | |
147 CPT::Report::HTML | |
148 | |
149 =head1 VERSION | |
150 | |
151 version 1.99.4 | |
152 | |
153 =head1 AUTHOR | |
154 | |
155 Eric Rasche <rasche.eric@yandex.ru> | |
156 | |
157 =head1 COPYRIGHT AND LICENSE | |
158 | |
159 This software is Copyright (c) 2014 by Eric Rasche. | |
160 | |
161 This is free software, licensed under: | |
162 | |
163 The GNU General Public License, Version 3, June 2007 | |
164 | |
165 =cut |