Fun facts about defined()

49 views
Skip to first unread message

David Schmitt

unread,
Jan 10, 2014, 3:52:49 AM1/10/14
to puppe...@googlegroups.com
Hi,

Please note the results of the following tests.

> root@testagent:/srv/dasz# echo 'warning(defined(undef))' | puppet apply
> Warning: Scope(Class[main]): true
> Notice: Compiled catalog for testagent.example.org in environment production in 0.06 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz# echo 'warning(defined($foo))' | puppet apply
> Warning: Scope(Class[main]): true
> Notice: Compiled catalog for testagent.example.org in environment production in 0.03 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz# echo 'warning(defined(undefined))' | puppet apply
> Warning: Scope(Class[main]): false
> Notice: Compiled catalog for testagent.example.org in environment production in 0.03 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz# echo 'warning(undef)' | puppet apply
> Warning: Scope(Class[main]):
> Notice: Compiled catalog for testagent.example.org in environment production in 0.02 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz# echo 'warning($foo)' | puppet apply
> Warning: Scope(Class[main]):
> Notice: Compiled catalog for testagent.example.org in environment production in 0.02 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz#
> root@testagent:/srv/dasz# echo 'warning(undefined)' | puppet apply
> Warning: Scope(Class[main]): undefined
> Notice: Compiled catalog for testagent.example.org in environment production in 0.02 seconds
> Notice: Finished catalog run in 0.13 seconds
> root@testagent:/srv/dasz# echo 'warning(defined(File["/blah"]))' | puppet apply
> Warning: Scope(Class[main]): false
> Notice: Compiled catalog for testagent.example.org in environment production in 0.08 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz# echo 'warning(File["/blah"])' | puppet apply
> Warning: Scope(Class[main]): File[/blah]
> Notice: Compiled catalog for testagent.example.org in environment production in 0.08 seconds
> Notice: Finished catalog run in 0.14 seconds
> root@testagent:/srv/dasz# puppet --version
> 3.4.2
> root@testagent:/srv/dasz#


It's sad, isn't it? At least I learned something today.


Regards, David

Erik Dalén

unread,
Jan 10, 2014, 9:51:40 AM1/10/14
to Puppet Developers
the value undef is passed as a empty string to the actual functions, not a ruby nil. So there's no way for a function to distinguish it from an actual empty string.

Unless you pass it in an array of course, like warning([undef]), then it will instead receive an array with the symbol :undef :)




--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/52CFB4E1.4070408%40dasz.at.
For more options, visit https://groups.google.com/groups/opt_out.



--
Erik Dalén
Reply all
Reply to author
Forward
0 new messages