| 1 | package Catmandu::Exporter::Mock; | ||
| 2 | |||
| 3 | 2 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 2 | our $VERSION = '1.0201_02'; | |
| 6 | |||
| 7 | 2 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 2 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 2 | with 'Catmandu::Exporter'; | |
| 11 | |||
| 12 | 2 | ▶ | has _data_ => (is => 'ro', default => sub {[]}); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | sub add { | ||
| 15 | 4 | ▶ | my ($self, $data) = @_; |
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 16 | 4 | push @{$self->_data_}, $data; | |
| 17 | 4 | 1; | |
| 18 | } | ||
| 19 | |||
| 20 | sub as_arrayref { | ||
| 21 | 2 | ▶ | my ($self) = @_; |
|
Subroutine
as_arrayref: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 22 | 2 | return $self->_data_; | |
| 23 | } | ||
| 24 | |||
| 25 | 2 | 1; | |
| 26 | |||
| 27 | __END__ | ||
| 28 | |||
| 29 | =pod | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Catmandu::Exporter::Mock - a exporter that doesn't export anything | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | # From the commandline | ||
| 38 | $ catmandu convert JSON --fix myfixes to Mock < /tmp/data.json | ||
| 39 | |||
| 40 | # From Perl | ||
| 41 | |||
| 42 | use Catmandu::Exporter::Mock; | ||
| 43 | |||
| 44 | # Print to STDOUT | ||
| 45 | my $exporter = Catmandu::Exporter::Mock->new(fix => 'myfix.txt'); | ||
| 46 | |||
| 47 | $exporter->add_many($arrayref); | ||
| 48 | $exporter->add_many($iterator); | ||
| 49 | $exporter->add_many(sub { }); | ||
| 50 | |||
| 51 | $exporter->add($hashref); | ||
| 52 | |||
| 53 | printf "exported %d objects\n" , $exporter->count; | ||
| 54 | |||
| 55 | # Get an array ref of all records exported | ||
| 56 | my $data = $exporter->as_arrayref; | ||
| 57 | |||
| 58 | =head1 DESCRIPTION | ||
| 59 | |||
| 60 | This exporter exports nothing and can be used as in situations where you e.g. export | ||
| 61 | data from a fix. Other the Null exporter, the Mock exporter will keep an internal | ||
| 62 | array of all the records exported which can be retrieved with the 'as_arrayref' method. | ||
| 63 | |||
| 64 | =head1 SEE ALSO | ||
| 65 | |||
| 66 | L<Catmandu::Exporter::Null> | ||
| 67 | |||
| 68 | =cut | ||