| 1 | package Exporter::Declare::Export; | ||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | our %OBJECT_DATA; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 130 | ▶ | sub required_specs {qw/ exported_by /} | ||||||||||||||||||||||||||
|
Subroutine
required_specs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 130 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 130 | my $class = shift; | |||||||||||||||||||||||||||
| 13 | 130 | my ( $item, %specs ) = @_; | |||||||||||||||||||||||||||
| 14 | 130 | my $self = bless( $item, $class ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 130 | for my $prop ( $self->required_specs ) { | |||||||||||||||||||||||||||
| 17 | croak "You must specify $prop when calling $class\->new()" | ||||||||||||||||||||||||||||
| 18 | 136 | ▶ | unless $specs{$prop}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 128 | $OBJECT_DATA{$self} = \%specs; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 128 | return $self; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 32 | ▶ | sub _data { | ||||||||||||||||||||||||||
|
Subroutine
_data: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 27 | 32 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 32 | ▶ | ($OBJECT_DATA{$self}) = @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 32 | $OBJECT_DATA{$self}; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 10 | ▶ | sub exported_by { | ||||||||||||||||||||||||||
|
Subroutine
exported_by: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 10 | shift->_data->{ exported_by }; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 86 | ▶ | sub inject { | ||||||||||||||||||||||||||
|
Subroutine
inject: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 86 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 86 | my ( $class, $name, @args ) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 86 | ▶ | carp( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | "Ignoring arguments importing (" | ||||||||||||||||||||||||||||
| 42 | . reftype($self) | ||||||||||||||||||||||||||||
| 43 | . ")$name into $class: " | ||||||||||||||||||||||||||||
| 44 | . join( ', ', @args ) | ||||||||||||||||||||||||||||
| 45 | ) if (@args); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 86 | ▶ | croak "You must provide a class and name to inject()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class and $name
MC/DC0%0/2
$class and $name
$class
$name
Truth table33%1/3
A and B
A= $classB= $name
| |||||||||||||||||||||||||||||
| 48 | unless $class && $name; | ||||||||||||||||||||||||||||
| 49 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 11 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 86 | *{"$class\::$name"} = $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 5 | delete $OBJECT_DATA{$self}; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 11 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 NAME | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Exporter::Declare::Export - Base class for all export objects. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | All exports are refs, and all are blessed. This class tracks some per-export | ||||||||||||||||||||||||||||
| 68 | information via an inside-out objects system. All things an export may need to | ||||||||||||||||||||||||||||
| 69 | do, such as inject itself into a package are handled here. This allows some | ||||||||||||||||||||||||||||
| 70 | complicated, or ugly logic to be abstracted out of the exporter and metadata | ||||||||||||||||||||||||||||
| 71 | classes. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 METHODS | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =over | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item $class->new( $ref, exported_by => $package, %data ) | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Create a new export from $ref. You must specify the name of the class doing the | ||||||||||||||||||||||||||||
| 80 | exporting. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =item $export->inject( $package, $name, @args ) | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | This will inject the export into $package under $name. @args are ignored in | ||||||||||||||||||||||||||||
| 85 | most cases. See L<Exporter::Declare::Export::Generator> for an example where | ||||||||||||||||||||||||||||
| 86 | they are used. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item $package = $export->exported_by() | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Returns the name of the package from which this export was originally exported. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =item @params = $export->required_specs() | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Documented for subclassing purposes. This should always return a list of | ||||||||||||||||||||||||||||
| 95 | required parameters at construction time. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item $export->DESTROY() | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Documented for subclassing purposes. This takes care of cleanup related to | ||||||||||||||||||||||||||||
| 100 | storing data in an inside-out objects system. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Chad Granum L<exodist7@gmail.com> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Copyright (C) 2010 Chad Granum | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Exporter-Declare is free software; Standard perl licence. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Exporter-Declare is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 115 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||||||||||||||||||||||||
| 116 | FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. | ||||||||||||||||||||||||||||