[librecat-dev] custom fix function with emit

Nicolas Steenlant Nicolas.Steenlant at UGent.be
Thu Jun 1 12:00:43 CEST 2017


Hi Carsten,

you weren’t capturing all the emitted perl code.
This should work:

sub emit {
   my ( $self, $fixer ) = @_;
    my $add_value      = $fixer->generate_var;
    my $perl                   = $fixer->emit_declare_vars( $add_value );

    my $path = $fixer->split_path( $self->value );
    my $key   = pop @$path;

    $perl .= $fixer->emit_walk_path($fixer->var, $path, sub {
        my $var = shift;

        $fixer->emit_get_key($var, $key, sub {
            my $var = shift;

            "if (is_string(${var})) {" .
                "${add_value} = ${var};" .
            "}";

        });
    });

    $perl;
}

Regarding your earlier question about closures vs code generation. It’s indeed no fun and more error prone to write these emitting fixes. Early versions of Catmandu used closures, but we found out after benchmarking that the method calling overhead became substantial in large fixe files. We're now looking into middle of the road solutions, like generating efficient helper code or analyzing and optimizing your perl code, that would avoid writing emitting code for fix authors.

Regards,
Nicolas

--
Nicolas Steenlant
software developer at University Library Ghent


On 1 Jun 2017, at 07:42, Klee, Carsten <Carsten.Klee at sbb.spk-berlin.de<mailto:Carsten.Klee at sbb.spk-berlin.de>> wrote:

sub emit {
   my ( $self, $fixer ) = @_;
    my $add_value      = $fixer->generate_var;
    my $perl                   = $fixer->emit_declare_vars( $add_value );

    my $path = $fixer->split_path( $self->value );
    my $key   = pop @$path;

    $fixer->emit_walk_path($fixer->var, $path, sub {
        my $var = shift;

        $fixer->emit_get_key($var, $key, sub {
            my $var = shift;

            $perl      .= "if (is_string(${var})) {" .
                "${add_value} = ${var};" .
            "}";

        });
    });
    $perl;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20170601/ab3a00a3/attachment.html>


More information about the librecat-dev mailing list