[librecat-dev] Message for Catmandu::Bind implementers
Patrick Hochstenbach
Patrick.Hochstenbach at UGent.be
Thu Jun 29 15:06:53 CEST 2017
Dear all
In Catmandu 1.06 processing of some Catmandu::Bind-s can be made faster by giving them the role ‘Catmandu::Fix::Bind::Group’.
Instead of writing in the Perl module for a Bind:
with 'Catmandu::Fix::Bind’;
use:
with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group’;
What does this do?
When you have a Bind in a Fix script like:
do
mybinder()
fix1()
fix2()
fix3()
end
Then Catmandu will first execute the `unit` method of the Bind and then execute `bind` on all fixes found in the Bind block. Given `data` as the currrent item that needs to be processed, in pseudo code this Bind block looks like:
m_data = mybinder->unit(data)
m_data = mybinder->bind(m_data, fix1)
m_data = mybinder->bind(m_data, fix2)
m_data = mybinder->bind(m_data, fix3)
data = mybinder->result(m_data)
When the `mybinder` has the role Catmandu::Fix::Bind::Group all the fixes in the Bind block wll be executed as one grouped anonymous function:
m_data = mybinder->unit(data)
m_data = mybinder->bind(m_data, sub { fix1; fix2; fix3 })
data = mybinder->result(m_data)
When you don’t need to explicitly run the ‘->bind’ on each separate fix in a Bind block then you want to use this Group role (probably is most Binds now available)
One counterexample where you don’t want Groups is for example the `maybe()` Bind which skips faulty fixes:
m_data = maybe->unit(data)
m_data = maybe->bind(m_data, fix1) # ok
m_data = maybe->bind(m_data, fix2) # dies and ignored
m_data = maybe->bind(m_data, fix3) # ignored because the previous was ignored
data = maybe->result(m_data)
Patrick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20170629/7d600c5e/attachment.asc>
More information about the librecat-dev
mailing list