Re: Various FreeBSD bits...

Matt Palmer
Wed, 14 Nov 2007 06:56:07 -0000

On Tue, Nov 13, 2007 at 01:54:37PM -0800, Sean Chittenden
wrote:
> >> eg:  right now I use:
> >>
> >> class freebsd {
> >>   $_cflags = $cflags ? { '''' =>
'''', default => $cflags }
> >>   $_cxxflags = $cxxflags ? { '''' =>
'''', default => $cxxflags }
> >>
> >>   $_supfile = $supfile ? { '''' =>
''/etc/supfile'', default =>
> >> $supfile }
> >>   $_kernconf = $kernconf ? { '''' =>
''GENERIC'', default => $kernconf }
> >>
> >>   $_portsdir = $portsdir ? { '''' =>
''/usr/ports'', default =>
> >> $portsdir }
> >>   $_srcdir = $srcdir ? { '''' =>
/usr/src'', default => $srcdir }
> >>   $_objdir = $objdir ? { '''' =>
/usr/obj'', default => $objdir }
> >>   ...
> >> }
> >
> > For the sake of all that is holy, USE A DEFINE!
>
>
> Hrm... am I missing the clever way of doing:
>
> define varfoo($var, $default) {
>    $ret = "\$_${var} = \$${var} ? { '''' =>
''${default}'', default => \$$
> {var} }
>    eval $ret
> }
>
> class freebsd {
>    varfoo {
>      portsdir: var => ''portsdir'', default =>
''/default'';
>    }
>
> }
>
> ??  I need to create $_foo...  if I could turn of the immutability of
> variables for a while and use $foo instead of $_foo, I''d be really
> happy.  :)
>
> $foo = ''/my/default'' if $foo == ''''
>
> This would be cool and very welcome:
>
> mother_doesnt_know_best {
>    $foo = $foo ? { '''' =>
''/my/default'', default = $foo }
> }

How about:

define freebsd($cflags = '''',
               $cxxflags = '''',
               $supfile = ''/etc/supfile'',
               $kernconf = ''GENERIC'',
               $portsdir = ''/usr/ports'',
               $srcdir = ''/usr/src'',
               $objdir = ''/usr/obj'')
{
	...
}

Sure, you need to do:

node ''fbsd'' {
	freebsd { fbsd:
		kernconf => ''RANDOM'',
		objdir => ''/tmp''
	}
}

Instead of:

node ''fbsd'' {
	$kernconf = ''RANDOM''
	$objdir = ''/tmp''

	include freebsd
}

But I reckon the former reads better *anyway*, and doesn''t pollute
namespaces nearly as badly.

The only reason why this might not work is if you really, really, really
need those variables set (if you needed them in other scopes) but my
reaction to that would be to fix those other collections, instead of faffing
around with setting Yet More Variables.

Matt''s 8th Puppet Code Smell: Cross-scope variables.

- Matt

--
English is about as pure as a cribhouse whore. We don''t just borrow
words; on occasion, English has pursued other languages down alleyways
to beat them unconscious and rifle their pockets for new vocabulary."
	-- James D. Nicoll, resident of rec.arts.sf.written