Update version according to OSCI-856
[packages/precise/mcollective.git] / doc / MCollective / Matcher.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6         <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
8         <title>Module: MCollective::Matcher</title>
9
10         <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
12         <script src="../js/jquery.js" type="text/javascript"
13                 charset="utf-8"></script>
14         <script src="../js/thickbox-compressed.js" type="text/javascript"
15                 charset="utf-8"></script>
16         <script src="../js/quicksearch.js" type="text/javascript"
17                 charset="utf-8"></script>
18         <script src="../js/darkfish.js" type="text/javascript"
19                 charset="utf-8"></script>
20
21 </head>
22 <body class="module">
23
24         <div id="metadata">
25                 <div id="file-metadata">
26                         <div id="file-list-section" class="section">
27                                 <h3 class="section-header">In Files</h3>
28                                 <div class="section-body">
29                                         <ul>
30                                         
31                                                 <li><a href="../lib/mcollective/matcher/scanner_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
32                                                         class="thickbox" title="lib/mcollective/matcher/scanner.rb">lib/mcollective/matcher/scanner.rb</a></li>
33                                         
34                                                 <li><a href="../lib/mcollective/matcher/parser_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
35                                                         class="thickbox" title="lib/mcollective/matcher/parser.rb">lib/mcollective/matcher/parser.rb</a></li>
36                                         
37                                                 <li><a href="../lib/mcollective/matcher_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
38                                                         class="thickbox" title="lib/mcollective/matcher.rb">lib/mcollective/matcher.rb</a></li>
39                                         
40                                         </ul>
41                                 </div>
42                         </div>
43
44                         
45                 </div>
46
47                 <div id="class-metadata">
48
49                         <!-- Parent Class -->
50                         
51
52                         <!-- Namespace Contents -->
53                         
54                         <div id="namespace-list-section" class="section">
55                                 <h3 class="section-header">Namespace</h3>
56                                 <ul class="link-list">
57                                         
58                                         <li><span class="type">CLASS</span> <a href="Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
59                                         
60                                         <li><span class="type">CLASS</span> <a href="Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
61                                         
62                                 </ul>
63                         </div>
64                         
65
66                         <!-- Method Quickref -->
67                         
68                         <div id="method-list-section" class="section">
69                                 <h3 class="section-header">Methods</h3>
70                                 <ul class="link-list">
71                                         
72                                         <li><a href="#M000065">::create_compound_callstack</a></li>
73                                         
74                                         <li><a href="#M000052">::create_function_hash</a></li>
75                                         
76                                         <li><a href="#M000059">::eval_compound_fstatement</a></li>
77                                         
78                                         <li><a href="#M000054">::eval_compound_statement</a></li>
79                                         
80                                         <li><a href="#M000053">::execute_function</a></li>
81                                         
82                                 </ul>
83                         </div>
84                         
85
86                         <!-- Included Modules -->
87                         
88                 </div>
89
90                 <div id="project-metadata">
91                         
92                         
93                         <div id="fileindex-section" class="section project-section">
94                                 <h3 class="section-header">Files</h3>
95                                 <ul>
96                                 
97                                         <li class="file"><a href="../COPYING.html">COPYING</a></li>
98                                 
99                                         <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
100                                 
101                                         <li class="file"><a href="../README.html">README</a></li>
102                                 
103                                         <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
104                                 
105                                         <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
106                                 
107                                         <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
108                                 
109                                         <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
110                                 
111                                         <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
112                                 
113                                         <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
114                                 
115                                         <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
116                                 
117                                         <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
118                                 
119                                         <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
120                                 
121                                         <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
122                                 
123                                         <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
124                                 
125                                         <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
126                                 
127                                         <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
128                                 
129                                         <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
130                                 
131                                         <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
132                                 
133                                         <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
134                                 
135                                         <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
136                                 
137                                 </ul>
138                         </div>
139                         
140
141                         <div id="classindex-section" class="section project-section">
142                                 <h3 class="section-header">Class Index
143                                         <span class="search-toggle"><img src="../images/find.png"
144                                                 height="16" width="16" alt="[+]"
145                                                 title="show/hide quicksearch" /></span></h3>
146                                 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
147                                 <fieldset>
148                                         <legend>Quicksearch</legend>
149                                         <input type="text" name="quicksearch" value=""
150                                                 class="quicksearch-field" />
151                                 </fieldset>
152                                 </form>
153
154                                 <ul class="link-list">
155                                 
156                                         <li><a href="../MCollective.html">MCollective</a></li>
157                                 
158                                         <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
159                                 
160                                         <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
161                                 
162                                         <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
163                                 
164                                         <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
165                                 
166                                         <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
167                                 
168                                         <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
169                                 
170                                         <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
171                                 
172                                         <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
173                                 
174                                         <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
175                                 
176                                         <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
177                                 
178                                         <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
179                                 
180                                         <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
181                                 
182                                         <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
183                                 
184                                         <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
185                                 
186                                         <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
187                                 
188                                         <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
189                                 
190                                         <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
191                                 
192                                         <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
193                                 
194                                         <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
195                                 
196                                         <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
197                                 
198                                         <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
199                                 
200                                         <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
201                                 
202                                         <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
203                                 
204                                         <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
205                                 
206                                         <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
207                                 
208                                         <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
209                                 
210                                         <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
211                                 
212                                         <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
213                                 
214                                         <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
215                                 
216                                         <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
217                                 
218                                         <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
219                                 
220                                         <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
221                                 
222                                         <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
223                                 
224                                         <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
225                                 
226                                         <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
227                                 
228                                         <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
229                                 
230                                         <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
231                                 
232                                         <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
233                                 
234                                         <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
235                                 
236                                         <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
237                                 
238                                         <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
239                                 
240                                         <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
241                                 
242                                         <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
243                                 
244                                         <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
245                                 
246                                         <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
247                                 
248                                         <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
249                                 
250                                         <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
251                                 
252                                         <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
253                                 
254                                         <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
255                                 
256                                         <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
257                                 
258                                         <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
259                                 
260                                         <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
261                                 
262                                         <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
263                                 
264                                         <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
265                                 
266                                         <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
267                                 
268                                         <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
269                                 
270                                         <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
271                                 
272                                         <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
273                                 
274                                         <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
275                                 
276                                         <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
277                                 
278                                         <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
279                                 
280                                         <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
281                                 
282                                         <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
283                                 
284                                         <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
285                                 
286                                         <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
287                                 
288                                         <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
289                                 
290                                         <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
291                                 
292                                         <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
293                                 
294                                         <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
295                                 
296                                         <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
297                                 
298                                         <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
299                                 
300                                         <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
301                                 
302                                         <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
303                                 
304                                         <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
305                                 
306                                         <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
307                                 
308                                         <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
309                                 
310                                         <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
311                                 
312                                         <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
313                                 
314                                         <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
315                                 
316                                         <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
317                                 
318                                         <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
319                                 
320                                         <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
321                                 
322                                         <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
323                                 
324                                         <li><a href="../Array.html">Array</a></li>
325                                 
326                                         <li><a href="../Dir.html">Dir</a></li>
327                                 
328                                         <li><a href="../Object.html">Object</a></li>
329                                 
330                                         <li><a href="../String.html">String</a></li>
331                                 
332                                         <li><a href="../Symbol.html">Symbol</a></li>
333                                 
334                                 </ul>
335                                 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
336                         </div>
337
338                         
339                 </div>
340         </div>
341
342         <div id="documentation">
343                 <h1 class="module">MCollective::Matcher</h1>
344
345                 <div id="description">
346                         <p>
347 A parser and scanner that creates a stack machine for a simple fact and
348 class matching language used on the CLI to facilitate a rich discovery
349 language
350 </p>
351 <p>
352 Language EBNF
353 </p>
354 <p>
355 compound = [&#8220;(&#8220;] expression [&#8220;)&#8221;]
356 {[&#8220;(&#8220;] expression [&#8220;)&#8221;]} expression =
357 [!|not]statement [&#8220;and&#8221;|&#8220;or&#8221;] [!|not] statement
358 char = A-Z | a-z | < | > | => | =< | _ | - |* | / { A-Z | a-z | < | > | =>
359 | =< | _ | - | * | / | } int = 0|1|2|3|4|5|6|7|8|9{|0|1|2|3|4|5|6|7|8|9|0}
360 </p>
361
362                 </div>
363
364                 <!-- Constants -->
365                 
366
367                 <!-- Attributes -->
368                 
369
370                 <!-- Methods -->
371                 
372                 <div id="public-class-method-details" class="method-section section">
373                         <h3 class="section-header">Public Class Methods</h3>
374
375                 
376                         <div id="create-compound-callstack-method" class="method-detail ">
377                                 <a name="M000065"></a>
378
379                                 <div class="method-heading">
380                                 
381                                         <span class="method-name">create_compound_callstack</span><span
382                                                 class="method-args">(call_string)</span>
383                                         <span class="method-click-advice">click to toggle source</span>
384                                 
385                                 </div>
386
387                                 <div class="method-description">
388                                         
389                                         <p>
390 Creates a callstack to be evaluated from a compound evaluation string
391 </p>
392                                         
393
394                                         
395                                         <div class="method-source-code"
396                                                 id="create-compound-callstack-source">
397 <pre>
398      <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 181</span>
399 181:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_compound_callstack</span>(<span class="ruby-identifier">call_string</span>)
400 182:       <span class="ruby-identifier">callstack</span> = <span class="ruby-constant">Matcher</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">call_string</span>).<span class="ruby-identifier">execution_stack</span>
401 183:       <span class="ruby-identifier">callstack</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">statement</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
402 184:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;fstatement&quot;</span>
403 185:           <span class="ruby-identifier">callstack</span>[<span class="ruby-identifier">i</span>][<span class="ruby-value str">&quot;fstatement&quot;</span>] = <span class="ruby-identifier">create_function_hash</span>(<span class="ruby-identifier">statement</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
404 186:         <span class="ruby-keyword kw">end</span>
405 187:       <span class="ruby-keyword kw">end</span>
406 188:       <span class="ruby-identifier">callstack</span>
407 189:     <span class="ruby-keyword kw">end</span></pre>
408                                         </div>
409                                         
410                                 </div>
411
412                                 
413                         </div>
414
415                 
416                         <div id="create-function-hash-method" class="method-detail ">
417                                 <a name="M000052"></a>
418
419                                 <div class="method-heading">
420                                 
421                                         <span class="method-name">create_function_hash</span><span
422                                                 class="method-args">(function_call)</span>
423                                         <span class="method-click-advice">click to toggle source</span>
424                                 
425                                 </div>
426
427                                 <div class="method-description">
428                                         
429                                         <p>
430 Helper creates a hash from a function call string
431 </p>
432                                         
433
434                                         
435                                         <div class="method-source-code"
436                                                 id="create-function-hash-source">
437 <pre>
438     <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 17</span>
439 17:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_function_hash</span>(<span class="ruby-identifier">function_call</span>)
440 18:       <span class="ruby-identifier">func_hash</span> = {}
441 19:       <span class="ruby-identifier">f</span> = <span class="ruby-value str">&quot;&quot;</span>
442 20:       <span class="ruby-identifier">func_parts</span> = <span class="ruby-identifier">function_call</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/(!=|&gt;=|&lt;=|&lt;|&gt;|=)/</span>)
443 21:       <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;r_compare&quot;</span>] = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">pop</span>
444 22:       <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">pop</span>
445 23:       <span class="ruby-identifier">func</span> = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">join</span>
446 24: 
447 25:       <span class="ruby-comment cmt"># Deal with dots in function parameters and functions without dot values</span>
448 26:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^.+\(.*\)$/</span>)
449 27:         <span class="ruby-identifier">f</span> = <span class="ruby-identifier">func</span>
450 28:       <span class="ruby-keyword kw">else</span>
451 29:         <span class="ruby-identifier">func_parts</span> = <span class="ruby-identifier">func</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;.&quot;</span>)
452 30:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;value&quot;</span>] = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">pop</span>
453 31:         <span class="ruby-identifier">f</span> = <span class="ruby-identifier">func_parts</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;.&quot;</span>)
454 32:       <span class="ruby-keyword kw">end</span>
455 33: 
456 34:       <span class="ruby-comment cmt"># Deal with regular expression matches</span>
457 35:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;r_compare&quot;</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\/.*\/$/</span>
458 36:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] = <span class="ruby-value str">&quot;=~&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;=&quot;</span>
459 37:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] = <span class="ruby-value str">&quot;!=~&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;!=&quot;</span>
460 38:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;r_compare&quot;</span>] = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;r_compare&quot;</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/^\/|\/$/</span>, <span class="ruby-value str">&quot;&quot;</span>))
461 39:       <span class="ruby-comment cmt"># Convert = operators to == so they can be propperly evaluated</span>
462 40:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;=&quot;</span>
463 41:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] = <span class="ruby-value str">&quot;==&quot;</span>
464 42:       <span class="ruby-keyword kw">end</span>
465 43: 
466 44:       <span class="ruby-comment cmt"># Grab function name and parameters from left compare string</span>
467 45:       <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;name&quot;</span>], <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>] = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;(&quot;</span>)
468 46:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;)&quot;</span>
469 47:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>] = <span class="ruby-keyword kw">nil</span>
470 48:       <span class="ruby-keyword kw">else</span>
471 49: 
472 50:         <span class="ruby-comment cmt"># Walk the function parameters from the front and from the</span>
473 51:         <span class="ruby-comment cmt"># back removing the first and last instances of single of</span>
474 52:         <span class="ruby-comment cmt"># double qoutes. We do this to handle the case where params</span>
475 53:         <span class="ruby-comment cmt"># contain escaped qoutes.</span>
476 54:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>] = <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;)&quot;</span>, <span class="ruby-value str">&quot;&quot;</span>)
477 55:         <span class="ruby-identifier">func_quotes</span> = <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>].<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/('|&quot;)/</span>)
478 56: 
479 57:         <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
480 58:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/'|&quot;/</span>)
481 59:             <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">i</span>)
482 60:             <span class="ruby-keyword kw">break</span>
483 61:           <span class="ruby-keyword kw">end</span>
484 62:         <span class="ruby-keyword kw">end</span>
485 63: 
486 64:         <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
487 65:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/'|&quot;/</span>)
488 66:             <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
489 67:             <span class="ruby-keyword kw">break</span>
490 68:           <span class="ruby-keyword kw">end</span>
491 69:         <span class="ruby-keyword kw">end</span>
492 70: 
493 71:         <span class="ruby-identifier">func_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>] = <span class="ruby-identifier">func_quotes</span>.<span class="ruby-identifier">join</span>
494 72:       <span class="ruby-keyword kw">end</span>
495 73: 
496 74:       <span class="ruby-identifier">func_hash</span>
497 75:     <span class="ruby-keyword kw">end</span></pre>
498                                         </div>
499                                         
500                                 </div>
501
502                                 
503                         </div>
504
505                 
506                         <div id="eval-compound-fstatement-method" class="method-detail ">
507                                 <a name="M000059"></a>
508
509                                 <div class="method-heading">
510                                 
511                                         <span class="method-name">eval_compound_fstatement</span><span
512                                                 class="method-args">(function_hash)</span>
513                                         <span class="method-click-advice">click to toggle source</span>
514                                 
515                                 </div>
516
517                                 <div class="method-description">
518                                         
519                                         <p>
520 Returns the result of an evaluated compound statement that includes a
521 function
522 </p>
523                                         
524
525                                         
526                                         <div class="method-source-code"
527                                                 id="eval-compound-fstatement-source">
528 <pre>
529      <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 135</span>
530 135:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">eval_compound_fstatement</span>(<span class="ruby-identifier">function_hash</span>)
531 136:       <span class="ruby-identifier">l_compare</span> = <span class="ruby-identifier">execute_function</span>(<span class="ruby-identifier">function_hash</span>)
532 137: 
533 138:       <span class="ruby-comment cmt"># Break out early and return false if the function returns nil</span>
534 139:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">l_compare</span>
535 140: 
536 141:       <span class="ruby-comment cmt"># Prevent unwanted discovery by limiting comparison operators</span>
537 142:       <span class="ruby-comment cmt"># on Strings and Booleans</span>
538 143:       <span class="ruby-keyword kw">if</span>((<span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">TrueClass</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">FalseClass</span>)) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>].<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/&lt;|&gt;/</span>))
539 144:         <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Cannot do &gt; and &lt; comparison on Booleans and Strings '#{l_compare} #{function_hash[&quot;operator&quot;]} #{function_hash[&quot;r_compare&quot;]}'&quot;</span>
540 145:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
541 146:       <span class="ruby-keyword kw">end</span>
542 147: 
543 148:       <span class="ruby-comment cmt"># Prevent backticks in function parameters</span>
544 149:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/`/</span>
545 150:         <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">&quot;Cannot use backticks in function parameters&quot;</span>)
546 151:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
547 152:       <span class="ruby-keyword kw">end</span>
548 153: 
549 154:       <span class="ruby-comment cmt"># Escape strings for evaluation</span>
550 155:       <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;r_compare&quot;</span>] = <span class="ruby-node">&quot;\&quot;#{function_hash[&quot;r_compare&quot;]}\&quot;&quot;</span> <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)  <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/=~|!=~/</span>))
551 156: 
552 157:       <span class="ruby-comment cmt"># Do a regex comparison if right compare string is a regex</span>
553 158:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(=~|!=~)/</span>
554 159:         <span class="ruby-comment cmt"># Fail if left compare value isn't a string</span>
555 160:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
556 161:           <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">&quot;Cannot do a regex check on a non string value.&quot;</span>)
557 162:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
558 163:         <span class="ruby-keyword kw">else</span>
559 164:           <span class="ruby-identifier">compare_result</span> = <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;r_compare&quot;</span>])
560 165:           <span class="ruby-comment cmt"># Flip return value for != operator</span>
561 166:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;operator&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;!=~&quot;</span>
562 167:             <span class="ruby-operator">!</span>((<span class="ruby-identifier">compare_result</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>)
563 168:           <span class="ruby-keyword kw">else</span>
564 169:             (<span class="ruby-identifier">compare_result</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span>
565 170:           <span class="ruby-keyword kw">end</span>
566 171:         <span class="ruby-keyword kw">end</span>
567 172:         <span class="ruby-comment cmt"># Otherwise evaluate the logical comparison</span>
568 173:       <span class="ruby-keyword kw">else</span>
569 174:         <span class="ruby-identifier">l_compare</span> = <span class="ruby-node">&quot;\&quot;#{l_compare}\&quot;&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">l_compare</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
570 175:         <span class="ruby-identifier">result</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;#{l_compare} #{function_hash[&quot;operator&quot;]} #{function_hash[&quot;r_compare&quot;]}&quot;</span>)
571 176:         (<span class="ruby-identifier">result</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">result</span>
572 177:       <span class="ruby-keyword kw">end</span>
573 178:     <span class="ruby-keyword kw">end</span></pre>
574                                         </div>
575                                         
576                                 </div>
577
578                                 
579                         </div>
580
581                 
582                         <div id="eval-compound-statement-method" class="method-detail ">
583                                 <a name="M000054"></a>
584
585                                 <div class="method-heading">
586                                 
587                                         <span class="method-name">eval_compound_statement</span><span
588                                                 class="method-args">(expression)</span>
589                                         <span class="method-click-advice">click to toggle source</span>
590                                 
591                                 </div>
592
593                                 <div class="method-description">
594                                         
595                                         <p>
596 Evaluates a compound statement
597 </p>
598                                         
599
600                                         
601                                         <div class="method-source-code"
602                                                 id="eval-compound-statement-source">
603 <pre>
604      <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 115</span>
605 115:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">eval_compound_statement</span>(<span class="ruby-identifier">expression</span>)
606 116:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\//</span>
607 117:         <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">has_cf_class?</span>(<span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
608 118:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/&gt;=|&lt;=|=|&lt;|&gt;/</span>
609 119:         <span class="ruby-identifier">optype</span> = <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/&gt;=|&lt;=|=|&lt;|&gt;/</span>)
610 120:         <span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span> = <span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">split</span>(<span class="ruby-identifier">optype</span>[<span class="ruby-value">0</span>])
611 121:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;&quot;</span>)[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>
612 122:           <span class="ruby-identifier">optype</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;=&quot;</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">optype</span> = <span class="ruby-value str">&quot;==&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">optype</span> = <span class="ruby-identifier">optype</span>[<span class="ruby-value">0</span>]
613 123:         <span class="ruby-keyword kw">else</span>
614 124:           <span class="ruby-identifier">optype</span> = <span class="ruby-value str">&quot;=~&quot;</span>
615 125:         <span class="ruby-keyword kw">end</span>
616 126: 
617 127:         <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">has_fact?</span>(<span class="ruby-identifier">name</span>,<span class="ruby-identifier">value</span>, <span class="ruby-identifier">optype</span>).<span class="ruby-identifier">to_s</span>
618 128:       <span class="ruby-keyword kw">else</span>
619 129:         <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">has_cf_class?</span>(<span class="ruby-identifier">expression</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
620 130:       <span class="ruby-keyword kw">end</span>
621 131:     <span class="ruby-keyword kw">end</span></pre>
622                                         </div>
623                                         
624                                 </div>
625
626                                 
627                         </div>
628
629                 
630                         <div id="execute-function-method" class="method-detail ">
631                                 <a name="M000053"></a>
632
633                                 <div class="method-heading">
634                                 
635                                         <span class="method-name">execute_function</span><span
636                                                 class="method-args">(function_hash)</span>
637                                         <span class="method-click-advice">click to toggle source</span>
638                                 
639                                 </div>
640
641                                 <div class="method-description">
642                                         
643                                         <p>
644 Returns the result of an executed function
645 </p>
646                                         
647
648                                         
649                                         <div class="method-source-code"
650                                                 id="execute-function-source">
651 <pre>
652      <span class="ruby-comment cmt"># File lib/mcollective/matcher.rb, line 78</span>
653  78:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">execute_function</span>(<span class="ruby-identifier">function_hash</span>)
654  79:       <span class="ruby-comment cmt"># In the case where a data plugin isn't present there are two ways we can handle</span>
655  80:       <span class="ruby-comment cmt"># the raised exception. The function result can either be false or the entire</span>
656  81:       <span class="ruby-comment cmt"># expression can fail.</span>
657  82:       <span class="ruby-comment cmt">#</span>
658  83:       <span class="ruby-comment cmt"># In the case where we return the result as false it opens us op to unexpected</span>
659  84:       <span class="ruby-comment cmt"># negation behavior.</span>
660  85:       <span class="ruby-comment cmt">#</span>
661  86:       <span class="ruby-comment cmt">#   !foo('bar').name = bar</span>
662  87:       <span class="ruby-comment cmt">#</span>
663  88:       <span class="ruby-comment cmt"># In this case the user would expect discovery to match on all machines where</span>
664  89:       <span class="ruby-comment cmt"># the name value of the foo function does not equal bar. If a non existent function</span>
665  90:       <span class="ruby-comment cmt"># returns false then it is posible to match machines where the name value of the</span>
666  91:       <span class="ruby-comment cmt"># foo function is bar.</span>
667  92:       <span class="ruby-comment cmt">#</span>
668  93:       <span class="ruby-comment cmt"># Instead we raise a DDLValidationError to prevent this unexpected behavior from</span>
669  94:       <span class="ruby-comment cmt"># happening.</span>
670  95: 
671  96:       <span class="ruby-identifier">result</span> = <span class="ruby-constant">Data</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;name&quot;</span>], <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;params&quot;</span>])
672  97: 
673  98:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;value&quot;</span>]
674  99:         <span class="ruby-keyword kw">begin</span>
675 100:           <span class="ruby-identifier">eval_result</span> = <span class="ruby-identifier">result</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">function_hash</span>[<span class="ruby-value str">&quot;value&quot;</span>])
676 101:         <span class="ruby-keyword kw">rescue</span>
677 102:           <span class="ruby-comment cmt"># If data field has not been set we set the comparison result to nil</span>
678 103:           <span class="ruby-identifier">eval_result</span> = <span class="ruby-keyword kw">nil</span>
679 104:         <span class="ruby-keyword kw">end</span>
680 105:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">eval_result</span>
681 106:       <span class="ruby-keyword kw">else</span>
682 107:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
683 108:       <span class="ruby-keyword kw">end</span>
684 109:     <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NoMethodError</span>
685 110:       <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;cannot execute discovery function '#{function_hash[&quot;name&quot;]}'. data plugin not found&quot;</span>)
686 111:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">DDLValidationError</span>
687 112:     <span class="ruby-keyword kw">end</span></pre>
688                                         </div>
689                                         
690                                 </div>
691
692                                 
693                         </div>
694
695                 
696                 </div>
697         
698
699         </div>
700
701
702         <div id="rdoc-debugging-section-dump" class="debugging-section">
703         
704                 <p>Disabled; run with --debug to generate this.</p>
705         
706         </div>
707
708         <div id="validator-badges">
709                 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
710                 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
711                         Rdoc Generator</a> 1.1.6</small>.</p>
712         </div>
713
714 </body>
715 </html>
716