[librecat-dev] convenience emit function
Klee, Carsten
Carsten.Klee at sbb.spk-berlin.de
Fri Jun 2 10:04:31 CEST 2017
Hi Nicolas!
This seems to limit the fix I want to create to return just a value, right? But I want to emit code in the end. Can I use this within a ‘emit’ function?
Cheers!
Carsten
Von: Nicolas Steenlant [mailto:Nicolas.Steenlant at UGent.be]
Gesendet: Freitag, 2. Juni 2017 09:48
An: Klee, Carsten
Betreff: Re: [librecat-dev] convenience emit function
Hi Carsten,
you can base your fix on this role for this common case:
https://github.com/LibreCat/Catmandu/blob/master/lib/Catmandu/Fix/SimpleGetValue.pm
Regards,
Nicolas
--
Nicolas Steenlant
software developer at University Library Ghent
On 2 Jun 2017, at 09:42, Klee, Carsten <Carsten.Klee at sbb.spk-berlin.de<mailto:Carsten.Klee at sbb.spk-berlin.de>> wrote:
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_*.
Cheers!
Carsten
---
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<mailto:carsten.klee at sbb.spk-berlin.de>
www.staatsbibliothek-berlin.de<http://www.staatsbibliothek-berlin.de/>
_______________________________________________
librecat-dev mailing list
- send list mails to librecat-dev at lists.uni-bielefeld.de<mailto:librecat-dev at lists.uni-bielefeld.de>
- to unsubscribe or change options, visit https://lists.uni-bielefeld.de/mailman2/cgi/unibi/listinfo/librecat-dev
- project website: http://librecat.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20170602/eab7cbfe/attachment.html>
More information about the librecat-dev
mailing list