1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
package Test::Inline::Content::Legacy;
=pod
=head1 NAME
Test::Inline::Content::Legacy - Test::Inline 2 Content Handler for legacy functions
=head1 SYNOPSIS
Custom script content generation using Test::Inline 2.000+ with a
custom generator functions
my $header = "....";
my $function = sub {
my $Object = shift;
my $Script = shift;
return $header . $Script->merged_content;
};
my $Inline = Test::Inline->new(
...
file_content => $function,
);
Migrating this same code to Test::Inline 2.100+ ContentHandler objects
my $header = "....";
my $function = sub {
my $Object = shift;
my $Script = shift;
return $header . $Script->merged_content;
};
my $ContentHandler = Test::Inline::Content::Legacy->new( $function );
my $Inline = Test::Inline->new(
...
ContentHandler => $ContentHandler,
);
=head1 DESCRIPTION
This class exists to provide a migration path for anyone using the custom
script generators in Test::Inline via the C<file_content> param.
The synopsis above pretty much says all you need to know.
=head1 METHODS
=cut
use strict;
use Params::Util qw{_CODE _INSTANCE};
use Test::Inline::Content ();
use vars qw{$VERSION @ISA};
BEGIN {
$VERSION = '2.212';
@ISA = 'Test::Inline::Content';
}
=pod
=head2 new $CODE_ref
The C<new> constructor for C<Test::Inline::Content::Legacy> takes a single
parameter of a C<CODE> reference, as you would have previously provided
directly to C<file_content>.
Returns a new C<Test::Inline::Content::Legacy> object, or C<undef> if not
passed a C<CODE> reference.
=cut
sub new {
my $class = ref $_[0] ? ref shift : shift;
my $self = $class->SUPER::new(@_);
$self->{coderef} = _CODE(shift) or return undef;
$self;
}
=pod
=head2 coderef
The C<coderef> accessor returns the C<CODE> reference for the object
=cut
sub coderef { $_[0]->{coderef} }
=pod
=head2 process $Inline $Script
The C<process> method works with the legacy function by passing the
L<Test::Inline> and L<Test::Inline::Script> arguments straight through
to the legacy function, and returning it's result as the return value.
=cut
sub process {
my $self = shift;
my $Inline = _INSTANCE(shift, 'Test::Inline') or return undef;
my $Script = _INSTANCE(shift, 'Test::Inline::Script') or return undef;
# Pass through the params, pass back the result
$self->coderef->( $Inline, $Script );
}
1;
=pod
=head1 SUPPORT
See the main L<SUPPORT|Test::Inline/SUPPORT> section.
=head1 AUTHOR
Adam Kennedy E<lt>adamk@cpan.orgE<gt>, L<http://ali.as/>
=head1 COPYRIGHT
Copyright 2004 - 2010 Adam Kennedy.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut
|