File: Mock.pm

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (68 lines) | stat: -rw-r--r-- 1,285 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package Catmandu::Exporter::Mock;

use Catmandu::Sane;

our $VERSION = '1.2024';

use Moo;
use namespace::clean;

with 'Catmandu::Exporter';

has _data_ => (is => 'ro', default => sub {[]});

sub add {
    my ($self, $data) = @_;
    push @{$self->_data_}, $data;
    1;
}

sub as_arrayref {
    my ($self) = @_;
    return $self->_data_;
}

1;

__END__

=pod

=head1 NAME

Catmandu::Exporter::Mock - a exporter that doesn't export anything

=head1 SYNOPSIS

    # From the commandline
    $ catmandu convert JSON --fix myfixes to Mock < /tmp/data.json

    # From Perl

    use Catmandu;

    # Print to STDOUT
    my $exporter = Catmandu->exporter('Mock',fix => 'myfix.txt');

    $exporter->add_many($arrayref);
    $exporter->add_many($iterator);
    $exporter->add_many(sub { });

    $exporter->add($hashref);

    printf "exported %d items\n" , $exporter->count;

    # Get an array ref of all records exported
    my $data = $exporter->as_arrayref;

=head1 DESCRIPTION

This exporter exports nothing and can be used as in situations where you e.g. export
data from a fix. Other the Null exporter, the Mock exporter will keep an internal
array of all the records exported which can be retrieved with the 'as_arrayref' method.

=head1 SEE ALSO

L<Catmandu::Exporter::Null>

=cut