I have a lot of this going on: -- class lighttpd { import "lighttpd.pp" } class mysql { import "mysql.pp" } class nagios { import "nagios.pp" } class netdisco { import "netdisco.pp" } class nfs_server { import "nfs.pp"} class openldap { import "openldap.pp" } -- But my client is trying to realize all of these, even though I don''t have any nodes defined. Can I use classes and imports this way? -- -- Perfection is just a word I use occasionally with mustard. --Atom Powers--
On Mar 28, 2007, at 4:57 PM, Atom Powers wrote:> I have a lot of this going on: > -- > class lighttpd { import "lighttpd.pp" } > class mysql { import "mysql.pp" } > class nagios { import "nagios.pp" } > class netdisco { import "netdisco.pp" } > class nfs_server { import "nfs.pp"} > class openldap { import "openldap.pp" } > -- > > But my client is trying to realize all of these, even though I don''t > have any nodes defined. > > Can I use classes and imports this way?No; imports happen at parse time, not compile time, so these files will all always get imported using this code. I mean, it''s syntactically legal, just probably not what you want. -- To define recursion, we must first define recursion. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On 3/28/07, Luke Kanies <luke@madstop.com> wrote:> On Mar 28, 2007, at 4:57 PM, Atom Powers wrote: > > -- > > class mysql { import "mysql.pp" } > > class nagios { import "nagios.pp" } > > class openldap { import "openldap.pp" } > > -- > > Can I use classes and imports this way? > > No; imports happen at parse time, not compile time, so these files > will all always get imported using this code. I mean, it''s > syntactically legal, just probably not what you want. >What is the "correct" way to do this? I could start each of those files with "class blah-blah {" and end it with an friendly "}"; but that pushes the logic out to each individual file, and I would really rather keep it centralized. -- -- Perfection is just a word I use occasionally with mustard. --Atom Powers--
On Mar 28, 2007, at 5:05 PM, Atom Powers wrote:> > What is the "correct" way to do this? > I could start each of those files with "class blah-blah {" and end it > with an friendly "}"; but that pushes the logic out to each individual > file, and I would really rather keep it centralized.The correct way is to put all of the code in the classes, each class in the appriately named file, and then import all of the files. E.g., the ''mysql'' class would be defined in the ''mysql.pp'' file. Really, unless you''re using modules I recommend putting these all into a classes/ subdirectory, and then just doing ''import "classes/ *"'' or something similar. But the key point is to put the code for that class within the class definition, rather than unencapsulated in a file. -- To succeed in the world it is not enough to be stupid, you must also be well-mannered. -- Voltaire --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com