From: Eloy P. <pe...@ch...> - 2013-05-09 14:40:14
|
Hi Jim, On 05/08/2013 11:03 PM, Jim Duda wrote: > In my user code, I can use the ON/OFF constants like this: > > set $side_porch ON; > > Where are these constants defined? They are defined in sub setup() in bin/mh. This is all of them: use constant; # To keep perl2exe happy use constant ON => 'on'; use constant OFF => 'off'; use constant DIM => 'dim'; use constant BRIGHTEN=> 'brighten'; use constant TOGGLE => 'toggle'; use constant STATUS => 'status'; use constant OPEN => 'open'; use constant CLOSE => 'close'; use constant OPENED => 'opened'; use constant CLOSED => 'closed'; use constant MOTION => 'motion'; use constant STILL => 'still'; > I want to use these same constants in some library .pm code, not sure how best to handle that. > > I've been using this, which works: > use constant; > use constant ON => 'on'; > use constant OFF => 'off'; > use constant PIO => 0; > use constant SENSE => 1; > use constant LATCH => 2; > > Unfortunately, I have to copy this set of code into each and every Package I want to use them in. > > There must be a better way .... Given that they are defined in bin/mh, it seems normal that libraries do not inherit them. I guess a better way could be to declare these constants in an object that gets inherited by pretty much all other objects, like Generic_Item. Cheers, Eloy Paris.- |