[Puppet Users] Re: Templates see numbers as strings

2013-06-26 Thread jcbollinger


On Tuesday, June 25, 2013 11:06:21 AM UTC-5, Claudio wrote:


 Given the manifest:

 $a = 1
 $b = 1 + 0
 $c = 1.1
 $d = 1.1 + 0
 $result = inline_template(
 a %= @a.class % %= @a %
 b %= @b.class % %= @b %
 c %= @c.class % %= @c %
 d %= @d.class % %= @d %
 )
 notify {
 $result:
 }



 The output is:

 a String 1
 b Fixnum 1
 c String 1.1
 d Float 1.1



 Is this working as intended?



I think so.  Puppet DSL does not require most string literals to be quoted, 
so it can distinguish numeric-form strings from actual numbers only by how 
they are produced or used.  I think it reasonable for Puppet to treat all 
values as strings except where it has specific reason to do otherwise.  
That's not the only possible approach, but I think it's probably the best 
fit for Puppet.

 


 How can I identify number types within the template without adding + 0 
 on the manifest? I'm aware that it's not a good idea to duck-type on 
 templates but I'm still wondering.


It depends on what you mean by that.  Apparently it's not about identifying 
whether Puppet is treating the value as numeric, so I guess it's about 
whether the value is numeric in form.  Perhaps you could do something along 
these lines:

%
  begin
num = Float(@maybe_num)
# It can be interpreted as a number
  rescue
# It's not numeric
  end
 % 

Really, though, this should not be necessary.  The DSL code calling the 
template should know how to use it appropriately (else it has no business 
using it at all).


John

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.




[Puppet Users] Re: Templates see numbers as strings

2013-06-25 Thread Claudio
I forgot to clarify that this was tested on versions 3.2.1 and 3.2.2.

On Tuesday, June 25, 2013 1:06:21 PM UTC-3, Claudio wrote:


 Given the manifest:

 $a = 1
 $b = 1 + 0
 $c = 1.1
 $d = 1.1 + 0
 $result = inline_template(
 a %= @a.class % %= @a %
 b %= @b.class % %= @b %
 c %= @c.class % %= @c %
 d %= @d.class % %= @d %
 )
 notify {
 $result:
 }



 The output is:

 a String 1
 b Fixnum 1
 c String 1.1
 d Float 1.1



 Is this working as intended?

 How can I identify number types within the template without adding + 0 
 on the manifest? I'm aware that it's not a good idea to duck-type on 
 templates but I'm still wondering.


 --
 Claudio



-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.