TT.pm

filter: Statementstmt 88.7% 55 / 62 Branchbran 65.0% 13 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 84.6% 77 / 91 CC 11 SCAR 21.4
CC
11
Cov
83%
tt_ok
13.2
BEGIN
1.0
BEGIN
1.0
CRAP 8.5
↑ Summary ._TT.pm »
1 package Test::TT;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use vars qw( @ISA $VERSION @EXPORT );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 @ISA = qw( Exporter );
14  
15 =head1 NAME
16  
17 Test::TT - Test::More-style wrapper around Template
18  
19 =head1 VERSION
20  
21 Version 0.01
22  
23 =cut
24  
25 2 $VERSION = '0.01';
26  
27 2 my $TEST = Test::Builder->new;
28  
29 =head1 SYNOPSIS
30  
31 use Test::Template tests => 1;
32  
33 my $table = build_display_table();
34 html_ok( $table, 'Built display table properly' );
35  
36 =head1 DESCRIPTION
37  
38 This module provides a few convenience methods for testing exception
39 based code. It is built with L<Test::Builder> and plays happily with
40 L<Test::More>.
41  
42 =head1 EXPORT
43  
44 C<tt_ok>
45  
46 =cut
47  
48 2 @EXPORT = qw( tt_ok );
49  
50 3 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
51 3 my $self = shift;
52 3 my $pack = caller;
53  
54 3 $TEST->exported_to($pack);
55 3 $TEST->plan(@_);
56  
57 3 $self->export_to_level( 1, $self, @EXPORT );
58  
59 3 return;
60 }
61  
62 =head2 tt_ok( [$tt_options, ] $tt_data, $name, $vars, $output )
63  
64 Checks to see that C<$tt_data> is valid TT.
65  
66 Checks to see if C<$tt_data> is valid TT. C<$tt_data> being blank is OK.
67 C<$tt_data> being undef is not. C<$tt_data> will be passed directly to
68 Template Toolkit, so you should pass a filename, a text reference or a
69 file handle (GLOB).
70  
71 If you pass a Template object, (<tt_ok()> will use that for parsing.
72  
73 C<$vars> will be passed to the template object, and should be a hashref. Can be skipped.
74  
75 C<$output> will be passed to the template object, and specifies what to the do with the output.
76 If not present tt_ok will silently eat all the output.
77  
78 =cut
79  
80 5 ▶sub tt_ok {
Subroutine tt_ok: called CC=11 SCAR=25.8
Pod documented
81 5 my $template;
82  
83 5 my $ok = 1;
84 5 ▶ if ( ref( $_[0] ) eq 'Template' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'Template') { } 0 5 5
85 0 $template = shift;
86 }
87 else {
88 5 $template = Template->new();
89 5 ▶ if ( !$template ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template) 0 5 5
90 0 $ok = 0;
91 }
92 }
93 5 my $tt_data = shift;
94 5 my $name = shift;
95 5 my $vars = shift;
96 5 my $output = shift;
97 5 my $data;
98  
99 5 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 5 5
100 0 $TEST->ok( 0, $name );
101 0 my $msg = 'Errors:';
102 0 ▶ $msg .= " $name" if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
103 0 $TEST->diag($msg);
104 0 $TEST->diag( Template->error() );
105 }
106  
107 5 ▶ if ( !$output ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output) 4 1 5
108 4 $output = \$data;
109 }
110  
111 5 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 5 0 5
112 5 $ok = defined $tt_data;
113 5 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 4 5
114 1 $TEST->ok( 0, $name );
115 }
116 }
117  
118 5 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 4 1 5
119 4 $ok = $template->process( $tt_data, $vars, $output );
120 4 $TEST->ok( $ok, $name );
121 4 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 2 2 4
122 2 my $msg = 'Errors:';
123 2 ▶ $msg .= " $name" if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 2 2
124 2 $TEST->diag($msg);
125 2 $TEST->diag( $template->error() );
126 }
127 }
128  
129 5 return $ok;
130 }
131  
132 =head1 BUGS
133  
134 Please report any bugs to (patches welcome):
135  
136 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Install-Debian
137  
138  
139 =head1 SEE ALSO
140  
141 L<Template>
142  
143  
144 =head1 ACKNOWLEGEMENTS
145  
146 Thanks to chromatic and Michael G Schwern for the excellent Test::Builder.
147  
148 Thanks to Andy Wardley for Template Toolkit.
149  
150 Thanks to Adrian Howard for writing Test::Exception, from which most of
151 this module is taken.
152  
153 =head1 AUTHOR
154  
155 BjE<oslash>rn-Olav Strand E<lt>bo@startsiden.noE<gt>
156  
157 =head1 LICENSE
158  
159 Copyright 2009 by BjE<oslash>rn-Olav Strand <bo@startsiden.no>.
160  
161 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
162  
163 Please note that these modules are not products of or supported by the
164 employers of the various contributors to the code.
165  
166 =cut
167  
168 2 1;
169  
↑ Summary ._TT.pm »