blib/lib/Audit/DBI/TT2.pm

filter: Statementstmt 100% 36 / 36 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 97.9% 48 / 49 CC 3 SCAR 3.1
CC
3
Cov
97%
html_dumper
2.0
format_results
2.0
BEGIN
1.0
CRAP 1.4
↑ Summary
1 package Audit::DBI::TT2;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Data::Dump qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use HTML::Entities qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use POSIX qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Template::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 =head1 NAME
15  
16 Audit::DBI::TT2 - A Template Toolkit plugin to display audit events recorded by L<Audit::DBI>.
17  
18  
19 =head1 VERSION
20  
21 Version 2.3.0
22  
23 =cut
24  
25 4 our $VERSION = '2.3.0';
26  
27  
28 =head1 SYNOPSIS
29  
30 In your Perl code:
31  
32 use Audit::DBI::TT2;
33 use Template;
34  
35 my $template = Template->new(
36 {
37 PLUGINS =>
38 {
39 audit => 'Audit::DBI::TT2',
40 },
41 }
42 ) || die $Template::ERROR;
43  
44 In your TT2 template:
45  
46 [% USE audit %]
47 [% FOREACH result IN audit.format_results( results ) %]
48 ...
49 [% END %]
50  
51 Note: a fully operational example of a search interface for Audit::DBI events
52 using this module for the display of the results is available in the
53 C<examples/> directory of this distribution.
54  
55  
56 =head1 FUNCTIONS
57  
58 =head2 format_results()
59  
60 Format the following fields for display as HTML:
61  
62 =over 4
63  
64 =item * diff
65  
66 (accessible as diff_formatted)
67  
68 =item * information
69  
70 (accessible as information_formatted)
71  
72 =item * event_time
73  
74 (accessible as event_time_formatted)
75  
76 =back
77  
78 [% FOREACH result IN audit.format_results( results ) %]
79 <div>
80 Formatted information: [% result.information_formatted %]<br/>
81 Formatted diff: [% result.diff_formatted %]<br/>
82 Formatted event time: [% result.event_time_formatted %]
83 </div>
84 [% END %]
85  
86 =cut
87  
88 sub format_results
89 1 ▶{
Subroutine format_results: called CC=2 SCAR=6.9
Pod documented
90 1 my ( $self, $results ) = @_;
91  
92 1 foreach my $result ( @$results )
93 {
94 1 $result->{information_formatted} = html_dumper( $result->get_information() );
95 1 $result->{diff_formatted} = html_dumper( $result->get_diff() );
96 $result->{event_time_formatted} = POSIX::strftime(
97 "%Y-%m-%d %H:%M:%S",
98 1 POSIX::localtime( $result->{event_time} ),
99 );
100 }
101  
102 1 return $results;
103 }
104  
105  
106 =head2 html_dumper()
107  
108 Format a data structure for display as HTML.
109  
110 my $formatted_data = Audit::DBI::TT2::html_dumper( $data );
111  
112 =cut
113  
114 sub html_dumper
115 3 ▶{
Subroutine html_dumper: called CC=2 SCAR=7.0
Pod documented
116 3 my ( $data ) = @_;
117 return undef
118 3 ▶ if !defined( $data );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 3 3
119  
120 3 my $string = Data::Dump::dump( $data );
121 3 $string = HTML::Entities::encode_entities( $string );
122 3 $string =~ s/ /&nbsp;/g;
123 3 $string =~ s/\n/<br\/>/g;
124  
125 3 return $string;
126 }
127  
128  
129 =head1 BUGS
130  
131 Please report any bugs or feature requests through the web interface at
132 L<https://github.com/guillaumeaubert/Audit-DBI-TT2/issues/new>.
133 I will be notified, and then you'll automatically be notified of progress on
134 your bug as I make changes.
135  
136  
137 =head1 SUPPORT
138  
139 You can find documentation for this module with the perldoc command.
140  
141 perldoc Audit::DBI::TT2
142  
143  
144 You can also look for information at:
145  
146 =over 4
147  
148 =item * GitHub's request tracker
149  
150 L<https://github.com/guillaumeaubert/Audit-DBI-TT2/issues>
151  
152 =item * AnnoCPAN: Annotated CPAN documentation
153  
154 L<http://annocpan.org/dist/Audit-DBI-TT2>
155  
156 =item * CPAN Ratings
157  
158 L<http://cpanratings.perl.org/d/Audit-DBI-TT2>
159  
160 =item * MetaCPAN
161  
162 L<https://metacpan.org/release/Audit-DBI-TT2>
163  
164 =back
165  
166  
167 =head1 AUTHOR
168  
169 L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, C<< <aubertg at cpan.org> >>.
170  
171  
172 =head1 ACKNOWLEDGEMENTS
173  
174 I originally developed this project for ThinkGeek
175 (L<http://www.thinkgeek.com/>). Thanks for allowing me to open-source it!
176  
177  
178 =head1 COPYRIGHT & LICENSE
179  
180 Copyright 2010-2017 Guillaume Aubert.
181  
182 This code is free software; you can redistribute it and/or modify it under the
183 same terms as Perl 5 itself.
184  
185 This program is distributed in the hope that it will be useful, but WITHOUT ANY
186 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
187 PARTICULAR PURPOSE. See the LICENSE file for more details.
188  
189 =cut
190  
191 4 1;
↑ Summary