Filtering subroutines
You can use Erlang expressions to conditionalize the firing of subroutines. For example, a consume operation has several notify subroutines, some of which only fire if certain conditions are met.
If the subr.spec
property of a subroutine notify or solicit operation contains
Erlang expressions, this content is used as a predicate
to determine whether the operation fires for a given call.
The operation only fires if the predicate returns true
. This result is
coerced to a boolean, so all the following results mean the same:
<<"true">>
"true"
1
true
Example | Description |
---|---|
<folder name="SubrFilters"> <service name="Subr" provision="subr" /> <mix name="Master"> <field name="master" type="string"/> <consume name="Master" fields="master" service="Subr"> <prop name="subr.spec" function="SubrFun"/> </consume> </mix> <mix name="Slave1"> <field name="slave1" type="string"/> <notify name="Slave1" clients="Subr" fields="slave1" service="Sequencer"> <prop name="params"><![CDATA[ master:slave1 ]]></prop> <prop name="subr.spec" function="SubrFun"><![CDATA[ get("master") == "foo". ]]></prop> </notify> </mix> <mix name="Slave2"> <field name="slave2" type="string"/> <notify name="Slave2" clients="Subr" fields="slave2" service="Sequencer"> <prop name="params"><![CDATA[ master:slave2 ]]></prop> <prop name="subr.spec" function="SubrFun"><![CDATA[ get("master") == "bar". ]]></prop> </notify> </mix> <mix name="Slave3"> <field name="slave3" type="string"/> <notify name="Slave3" clients="Subr" fields="slave3" service="Sequencer"> <prop name="params"><![CDATA[ master:slave3 ]]></prop> <prop name="subr.spec" function="SubrFun"/> </notify> </mix> </folder> |
The fields of the operations were all bound to the same parameter,
master . The
If a subroutine has no predicate, it is the same as having a predicate whose
result is always Use the built-in Erlang functions Important: Target the parameter - not the field - names to access the values.
|