File: Builder.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 (59 lines) | stat: -rw-r--r-- 1,177 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
package Catmandu::Fix::Builder;

use Catmandu::Sane;

our $VERSION = '1.2024';

use Catmandu::Fix;
use Catmandu::Util qw(is_value require_package);
use Moo::Role;
use namespace::clean;

with 'Catmandu::Fix::Base';

has fixer => (is => 'lazy');

sub emit {
    my ($self, $fixer) = @_;
    my $data_var = $fixer->var;
    my $sub_var  = $fixer->capture($self->fixer);
    my $val      = $self->_emit_call($sub_var, $data_var);
    $self->_emit_assign($data_var, $val);
}

1;

__END__

=pod

=head1 NAME

Catmandu::Fix::Builder - Base role for Catmandu fixes

=head1 DESCRIPTION

This role expects a C<_build_fixer> method that produces a coderef that
transforms the data.  Used in combination with L<Catmandu::Path>
implementations, data manipulations can be described in a relatively high-level
way. Most fixes shipped with Catmandu work this way and can be used as a
starting point to write your own fixes.

=head1 SYNOPSIS

    package Catmandu::Fix::my_fix;

    use Catmandu::Sane;
    use Moo;

    with 'Catmandu::Fix::Builder';

    sub _build_fixer {
        sub {
            my ($data) = @_;
            $data->{foo} = 'bar';
            $data;
        }
    }

=cut