File Coverage

lib/Test/WWW/Mechanize/Driver/MagicValues.pm
Criterion Covered Total %
statement 27 46 58.7
branch 0 2 0.0
condition n/a
subroutine 9 12 75.0
pod n/a
total 36 60 60.0


line stmt bran cond sub pod time code
1              
2             =head1 NAME
3              
4             Test::WWW::Mechanize::Driver::MagicValues - Define Magic Value classes
5              
6             =head1 Magic Classes
7              
8             =cut
9              
10             =head2 FileContents
11              
12             Stringification of a scalar reference in this class will slurp the file
13             whose name was stored in the reference.
14              
15             my $file = "Foo.txt";
16             print bless(\$file, "FileContents"); # prints contents of Foo.txt
17              
18             =cut
19              
20             package FileContents;
21 9     9   80 use strict; use warnings;
  9     9   22  
  9         400  
  9         74  
  9         25  
  9         1272  
22             our $VERSION = 1.0;
23              
24             use overload '""' => sub {
25 0     0   0 my $x = shift;
26 0 0       0 open my $F, "<", $$x or die "Can't open $$x for reading: $!";
27 0         0 local $/;
28 0         0 return scalar <$F>;
29 9     9   58 };
  9         18  
  9         117  
30              
31              
32             =head2 ApplyTemplate
33              
34             Stringification of a scalar reference in this class will pass the text of
35             the reference through Template.pm. Some useful variables will be defined.
36              
37             my $tmpl = "[% now.strftime('%Y-%m-%d') %]";
38             print bless(\$tmpl, "ApplyTemplate"); # prints current date
39              
40             =over 4
41              
42             =item t
43              
44             The value of C<$Test::WWW::Mechanize::Driver::CURRENT_GROUP>
45              
46             =item now
47              
48             The current date as a DateTime object.
49              
50             =back
51              
52             =cut
53              
54             package ApplyTemplate;
55 9     9   891 use strict; use warnings;
  9     9   20  
  9         246  
  9         52  
  9         18  
  9         1508  
56             our $VERSION = 1.0;
57              
58             use overload '""' => sub {
59 0     0   0 my $x = shift;
60 0         0 require Template;
61 0         0 require DateTime;
62 0         0 my $template = Template->new();
63 0         0 my $input = $$x;
64 0         0 my $output;
65 0         0 $template->process( \$input, {
66             t => $Test::WWW::Mechanize::Driver::CURRENT_GROUP,
67             now => DateTime->now,
68             },
69             \$output );
70 0         0 return $output;
71 9     9   164 };
  9         23  
  9         65  
72              
73              
74             =head2 Stacked
75              
76             Stringification of a scalar reference in this class will slurp the file
77             whose name was stored in the reference.
78              
79             my @stack = ( "Foo.txt", "FileContents", "ApplyTemplate" );
80             print bless(\@stack, "Stacked"); # fills in and prints template in Foo.txt
81              
82             =cut
83              
84             package Stacked;
85 9     9   598 use strict; use warnings;
  9     9   15  
  9         392  
  9         48  
  9         22  
  9         1193  
86             our $VERSION = 1.0;
87              
88             use overload '""' => sub {
89 0     0     my $x = shift;
90 0           my $value = $$x[0];
91 0           for my $pkg (@$x[1..$#{$x}]) {
  0            
92 0           my $blessed = bless \$value, $pkg;
93 0           $value = "$blessed";
94             }
95 0           return $value;
96 9     9   49 };
  9         20  
  9         77  
97              
98              
99              
100             1;
101              
102             __END__