[librecat-dev] convenience emit function

Klee, Carsten Carsten.Klee at sbb.spk-berlin.de
Fri Jun 2 09:42:13 CEST 2017

Hi Catmanduers again!

I'm not sure that this is reasonable. But for me it seems like, when creating a fix, you have recurrent tasks like "get me a value from a given path", "set a value for a given path" or "delete value for a given path".

To achieve this you always have to write code like:

my $my_var  = $fixer->generate_var;
my $perl         = $fixer->emit_declare_vars($my_var );
my $path        = $fixer->split_path( $self->path );
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})) {" .
                    "${my_var} = ${var};" .

But wouldn't it be more convenient (and less error prone) to provide functions for such recurrent tasks? Like

my $perl = $fixer->emit_get_string('my_var', $path, $fixer->var);

which should do the same like the code above. Or

my $perl = $fixer->emit_get_value('my_var', $path, $fixer->var);

which also should do the same, but without the 'is_string' check. And the same for emit_set_* and emit_delete_*.


Carsten Klee
Zeitschriftendatenbank (ZDB)
Staatsbibliothek zu Berlin - Preußischer Kulturbesitz

Potsdamer Straße 33
10785 Berlin

Tel.:   +49 30 266-43 44 02
Fax:    +49 30 266-33 44 01
carsten.klee at sbb.spk-berlin.de

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

More information about the librecat-dev mailing list