| 1 | package Exporter::Declare::Export::Generator; | ||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use base 'Exporter::Declare::Export::Sub'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use Exporter::Declare::Export::Variable; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 6 | ▶ | sub required_specs { | ||||||||
|
Subroutine
required_specs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 10 | 6 | my $self = shift; | |||||||||
| 11 | return( | ||||||||||
| 12 | 6 | $self->SUPER::required_specs(), | |||||||||
| 13 | qw/ type /, | ||||||||||
| 14 | ); | ||||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 13 | ▶ | sub type { shift->_data->{ type }} | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | |||||||||||
| 19 | 6 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 20 | 6 | my $class = shift; | |||||||||
| 21 | 6 | ▶ | croak "Generators must be coderefs, not " . ref($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | unless ref( $_[0] ) eq 'CODE'; | ||||||||||
| 23 | 6 | $class->SUPER::new( @_ ); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 9 | ▶ | sub generate { | ||||||||
|
Subroutine
generate: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||
| 27 | 9 | my $self = shift; | |||||||||
| 28 | 9 | my ( $import_class, @args ) = @_; | |||||||||
| 29 | 9 | my $ref = $self->( $self->exported_by, $import_class, @args ); | |||||||||
| 30 | |||||||||||
| 31 | return Exporter::Declare::Export::Sub->new( | ||||||||||
| 32 | $ref, | ||||||||||
| 33 | 9 | ▶ | %{ $self->_data }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | ) if $self->type eq 'sub'; | ||||||||||
| 35 | |||||||||||
| 36 | return Exporter::Declare::Export::Variable->new( | ||||||||||
| 37 | $ref, | ||||||||||
| 38 | 3 | ▶ | %{ $self->_data }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | ) if $self->type eq 'variable'; | ||||||||||
| 40 | |||||||||||
| 41 | return $self->type->new( | ||||||||||
| 42 | $ref, | ||||||||||
| 43 | 0 | %{ $self->_data }, | |||||||||
| 44 | ); | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 9 | ▶ | sub inject { | ||||||||
|
Subroutine
inject: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | 9 | my $self = shift; | |||||||||
| 49 | 9 | my ( $class, $name, @args ) = @_; | |||||||||
| 50 | 9 | $self->generate( $class, @args )->inject( $class, $name ); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 5 | 1; | |||||||||
| 54 | |||||||||||
| 55 | =head1 NAME | ||||||||||
| 56 | |||||||||||
| 57 | Exporter::Declare::Export::Generator - Export class for exports that should be | ||||||||||
| 58 | generated when imported. | ||||||||||
| 59 | |||||||||||
| 60 | =head1 DESCRIPTION | ||||||||||
| 61 | |||||||||||
| 62 | Export class for exports that should be generated when imported. | ||||||||||
| 63 | |||||||||||
| 64 | =head1 OVERRIDEN METHODS | ||||||||||
| 65 | |||||||||||
| 66 | =over 4 | ||||||||||
| 67 | |||||||||||
| 68 | =item $class->new( $ref, $ref, exported_by => $package, type => $type, %data ) | ||||||||||
| 69 | |||||||||||
| 70 | You must specify the type as 'sub' or 'variable'. | ||||||||||
| 71 | |||||||||||
| 72 | =item $export->inject( $package, $name, @args ) | ||||||||||
| 73 | |||||||||||
| 74 | Calls generate() with @args to create a generated export. The new export is | ||||||||||
| 75 | then injected. | ||||||||||
| 76 | |||||||||||
| 77 | =back | ||||||||||
| 78 | |||||||||||
| 79 | =head1 ADDITIONAL METHODS | ||||||||||
| 80 | |||||||||||
| 81 | =over 4 | ||||||||||
| 82 | |||||||||||
| 83 | =item $new = $export->generate( $import_class, @args ) | ||||||||||
| 84 | |||||||||||
| 85 | Generates a new export object. | ||||||||||
| 86 | |||||||||||
| 87 | =item $type = $export->type() | ||||||||||
| 88 | |||||||||||
| 89 | Returns the type of object to be generated (sub or variable) | ||||||||||
| 90 | |||||||||||
| 91 | =back | ||||||||||
| 92 | |||||||||||
| 93 | =head1 AUTHORS | ||||||||||
| 94 | |||||||||||
| 95 | Chad Granum L<exodist7@gmail.com> | ||||||||||
| 96 | |||||||||||
| 97 | =head1 COPYRIGHT | ||||||||||
| 98 | |||||||||||
| 99 | Copyright (C) 2010 Chad Granum | ||||||||||
| 100 | |||||||||||
| 101 | Exporter-Declare is free software; Standard perl licence. | ||||||||||
| 102 | |||||||||||
| 103 | Exporter-Declare is distributed in the hope that it will be useful, but | ||||||||||
| 104 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||||||
| 105 | FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. | ||||||||||