Test::Inline::Content::Legacy - Test::Inline 2 Content Handler for legacy functions


Test-Inline documentation Contained in the Test-Inline distribution.

Index


Code Index:

NAME

Top

Test::Inline::Content::Legacy - Test::Inline 2 Content Handler for legacy functions

SYNOPSIS

Top

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,
  	);

DESCRIPTION

Top

This class exists to provide a migration path for anyone using the custom script generators in Test::Inline via the file_content param.

The synopsis above pretty much says all you need to know.

METHODS

Top

new $CODE_ref

The new constructor for Test::Inline::Content::Legacy takes a single parameter of a CODE reference, as you would have previously provided directly to file_content.

Returns a new Test::Inline::Content::Legacy object, or undef if not passed a CODE reference.

coderef

The coderef accessor returns the CODE reference for the object

process $Inline $Script

The process method works with the legacy function by passing the Test::Inline and Test::Inline::Script arguments straight through to the legacy function, and returning it's result as the return value.

SUPPORT

Top

See the main SUPPORT section.

AUTHOR

Top

Adam Kennedy <adamk@cpan.org>, http://ali.as/

COPYRIGHT

Top


Test-Inline documentation Contained in the Test-Inline distribution.
package Test::Inline::Content::Legacy;

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';
}

sub new {
	my $class = ref $_[0] ? ref shift : shift;
	my $self  = $class->SUPER::new(@_);
	$self->{coderef} = _CODE(shift) or return undef;
	$self;
}

sub coderef { $_[0]->{coderef} }

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;