Exporter-Extensible

 view release on metacpan or  search on metacpan

t/21-export-attribute.t  view on Meta::CPAN

#! /usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Scalar::Util 'weaken';

use_ok( 'Exporter::Extensible' ) or BAIL_OUT;

my @tests= (
	[ 'export a sub',
		'sub alpha :Export {}',
		q{ is_deeply(\%Example::EXPORT, { alpha => \&Example::alpha }) }
	],
	[ 'export a sub in groups',
		'sub alpha :Export( :group1 ) {}',
		q{ is_deeply(\%Example::EXPORT, { alpha => \&Example::alpha }) },
		q{ is_deeply(\%Example::EXPORT_TAGS, { group1 => [qw( alpha )] }) }
	],
	[ 'export sub with alt name with groups',
		'sub alpha :Export( :group2 beta :group3 ) {}',
		q{ is_deeply(\%Example::EXPORT, { beta => \&Example::alpha }) },
		q{ is_deeply(\%Example::EXPORT_TAGS, { group2 => ["beta"], group3 => ["beta"] }) }
	],
	[ 'export multiple sub aliases in multiple groups',
		'sub alpha :Export( :group1 alpha beta :group2 ) {}',
		q{ is_deeply(\%Example::EXPORT, { alpha => \&Example::alpha, beta => \&Example::alpha }) },
		q{ is_deeply(\%Example::EXPORT_TAGS, { group1 => ["alpha","beta"], group2 => ["alpha","beta"] }) }
	],
	[ 'multiple exports of same sub',
		'sub alpha :Export( alpha :group1 ) Export(beta :group2) {}',
		q{ is_deeply(\%Example::EXPORT, { alpha => \&Example::alpha, beta => \&Example::alpha }) },
		q{ is_deeply(\%Example::EXPORT_TAGS, { group1 => ["alpha"], group2 => ["beta"] }) }
	],
	[ 'export a generator',
		'sub _generate_alpha :Export(=) {}',
		q{ is_deeply(\%Example::EXPORT, { alpha => '_generate_alpha' }) },
	],
	[ 'export a generator of scalar',
		'sub _generateScalar_alpha :Export(=$) {}',
		q{ is_deeply(\%Example::EXPORT, { '$alpha' => '_generateScalar_alpha' }) },
	],
	[ 'export a generator of array',
		'sub _generateARRAY_alpha :Export(=@) {}',
		q{ is_deeply(\%Example::EXPORT, { '@alpha' => '_generateARRAY_alpha' }) },
	],
	[ 'export a generator of array',
		'sub alpha :Export(=@) {}',
		q{is_deeply(\%Example::EXPORT, { '@alpha' => 'alpha' })},
	],
	[ 'export a generator of different name',
		'sub build_alpha :Export(=@alpha) {}',
		q{is_deeply(\%Example::EXPORT, { '@alpha' => 'build_alpha' })},
	],
	[ 'export a generator of different name having generator prefix',
		'sub _generateScalar_alpha :Export(=$foo) {}',
		q{is_deeply(\%Example::EXPORT, { '$foo' => '_generateScalar_alpha' })},
	],
	[ 'export a generator and its generated thing',
		'sub _generate_alpha :Export(generate_alpha =@alpha) {}',
		q{is_deeply(\%Example::EXPORT,
			{ 'generate_alpha' => \&Example::_generate_alpha,
			  '@alpha'         => '_generate_alpha'
			} )
		}
	],



( run in 2.056 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )