| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::Inline::Content::Simple; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =pod | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Test::Inline::Content::Simple - Simple templating Content Handler | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | In your inline2test.tpl | 
| 12 |  |  |  |  |  |  | ---------------------- | 
| 13 |  |  |  |  |  |  | #!/usr/bin/perl -w | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | use strict; | 
| 16 |  |  |  |  |  |  | use Test::More [% plan %]; | 
| 17 |  |  |  |  |  |  | $| = 1; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | [% tests %] | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | 1; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | It is relatively common to want to customise the contents of the generated | 
| 30 |  |  |  |  |  |  | test files to set up custom environment things on an all-scripts basis, | 
| 31 |  |  |  |  |  |  | rather than file by file (using =begin SETUP blocks). | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | C lets you use a very simple Template Toolkit | 
| 34 |  |  |  |  |  |  | style template to define this information. | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | It contains only two tags, C and C. | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | The C tag will be inserted as either C 123> or C<'no_plan'>. | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | The C tag will be replaced by the actual testing code. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 METHODS | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =cut | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 12 |  |  | 12 |  | 1201 | use strict; | 
|  | 12 |  |  |  |  | 21 |  | 
|  | 12 |  |  |  |  | 371 |  | 
| 47 | 12 |  |  | 12 |  | 1133 | use File::Slurp  (); | 
|  | 12 |  |  |  |  | 4338 |  | 
|  | 12 |  |  |  |  | 219 |  | 
| 48 | 12 |  |  | 12 |  | 65 | use Params::Util qw{_INSTANCE}; | 
|  | 12 |  |  |  |  | 25 |  | 
|  | 12 |  |  |  |  | 482 |  | 
| 49 | 12 |  |  | 12 |  | 94 | use Test::Inline::Content (); | 
|  | 12 |  |  |  |  | 23 |  | 
|  | 12 |  |  |  |  | 216 |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 12 |  |  | 12 |  | 53 | use vars qw{$VERSION @ISA}; | 
|  | 12 |  |  |  |  | 21 |  | 
|  | 12 |  |  |  |  | 742 |  | 
| 52 |  |  |  |  |  |  | BEGIN { | 
| 53 | 12 |  |  | 12 |  | 30 | $VERSION = '2.213'; | 
| 54 | 12 |  |  |  |  | 6648 | @ISA     = 'Test::Inline::Content'; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | ##################################################################### | 
| 62 |  |  |  |  |  |  | # Constructor and Accessors | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =pod | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head2 new $filename | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | Manually create a new C object. Takes as | 
| 69 |  |  |  |  |  |  | parameter a single filename which should contain the template code. | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | Returns a new C object, or C on error. | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub new { | 
| 76 | 1 | 50 |  | 1 | 1 | 1236 | my $class = ref $_[0] ? ref shift : shift; | 
| 77 | 1 | 50 | 33 |  |  | 28 | my $file  = (defined $_[0] and -r $_[0]) ? shift : return undef; | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | # Create the object | 
| 80 | 1 | 50 |  |  |  | 13 | my $self  = $class->SUPER::new() or return undef; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | # Load, check and add the file | 
| 83 | 1 | 50 |  |  |  | 8 | my $template = File::Slurp::read_file( $file ) or return undef; | 
| 84 | 1 | 50 |  |  |  | 137 | $template =~ /\[%\s+tests\s+\%\]/              or return undef; | 
| 85 |  |  |  |  |  |  | # $template =~ /\[\%\s+plan\s+\%\]/              or return undef; | 
| 86 | 1 |  |  |  |  | 4 | $self->{template} = $template; | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 1 |  |  |  |  | 3 | $self; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =pod | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =head2 template | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | The C accessor returns the template content for the object | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =cut | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 1 |  |  | 1 | 1 | 440 | sub template { $_[0]->{template} } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | ##################################################################### | 
| 106 |  |  |  |  |  |  | # Test::Inline::Content Methods | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =pod | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head2 process $Inline, $Script | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | The C method is unchanged from C. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =cut | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub process { | 
| 117 | 1 |  |  | 1 | 1 | 2 | my $self   = shift; | 
| 118 | 1 | 50 |  |  |  | 12 | my $Inline = _INSTANCE(shift, 'Test::Inline')         or return undef; | 
| 119 | 1 | 50 |  |  |  | 13 | my $Script = _INSTANCE(shift, 'Test::Inline::Script') or return undef; | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | # Get the merged content | 
| 122 | 1 |  |  |  |  | 6 | my $content = $Script->merged_content; | 
| 123 | 1 | 50 |  |  |  | 4 | return undef unless defined $content; | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | # Determine a plan | 
| 126 | 1 |  |  |  |  | 4 | my $tests = $Script->tests; | 
| 127 | 1 | 50 |  |  |  | 5 | my $plan  = defined $tests | 
| 128 |  |  |  |  |  |  | ? "tests => $tests" | 
| 129 |  |  |  |  |  |  | : "'no_plan'"; | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | # Replace the two values | 
| 132 | 1 |  |  |  |  | 3 | my $script = $self->{template}; | 
| 133 | 1 |  |  |  |  | 7 | $script =~ s/\[%\s+tests\s+\%\]/$content/; | 
| 134 | 1 |  |  |  |  | 5 | $script =~ s/\[\%\s+plan\s+\%\]/$plan/; | 
| 135 |  |  |  |  |  |  |  | 
| 136 | 1 |  |  |  |  | 4 | $script; | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | 1; | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =pod | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =head1 SUPPORT | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | See the main L section. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =head1 AUTHOR | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | Adam Kennedy Eadamk@cpan.orgE, L | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | Copyright 2004 - 2013 Adam Kennedy. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This program is free software; you can redistribute | 
| 156 |  |  |  |  |  |  | it and/or modify it under the same terms as Perl itself. | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | The full text of the license can be found in the | 
| 159 |  |  |  |  |  |  | LICENSE file included with this module. | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =cut |