Re: [mh] eval'ing perl to create MH mqtt objects
Tom MacLean <[email protected]> Thu, 28 Oct 2021 10:49:51 -0400
| Newsgroups | gmane.comp.misc.misterhouse.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Brian,
I can create objects in my MHT files (as expected):
CODE, $Basement_Niche_Lights_mqtt = new mqtt_Item($mqtt_1, "basement/niche/light/state");
But if I try to create one in a script, like this:
$Basement_Landing_mqtt = new mqtt_Item($mqtt_1, "basement/landing/state");
I get the complaint about "Global symbol "$Basement_Landing_mqtt" requires explicit package name'.
I'll try to play around with the amount of white space as you suggest. Indeed the MHP files created from the MHT ones do have a goodly amount of white space.
Best Regards,
Tom
On 2021-10-27 17:29, Brian M wrote:
> I'm not sure I completely understand your problem, but MH is funky
> about non-MH objects. It looks for "->new" statements and assumes
> those are for its own objects. I use a lot of my own objects, and they
> work, but you'll be in better shape if you precede the "...->new"
> statement with 4 or more spaces (not tabs). So "my $x =
> My::Object->new();" will get you in trouble. " my $x =
> My::Object->new();" -- the same thing but with four spaces in front
> of it -- will work. I only found this by reading through the MH
> user-code parsing logic. If it finds the line begins with four or
> more blanks (actually maybe three or more, don't remember), it doesn't
> treat the object as one of its own objects.
> Not sure that's the problem you're having, but maybe it'll help.
> -Brian M.
> On 10/27/21 1:21 PM, Tom MacLean wrote:
>>
>> So, I have played with this more. I notice that I cannot create any objects in my *.pl scripts -- if I do I get the complaint that "Global symbol $x requires explicit package name". Is there a workaround for that, or must all objects be created in MHT files?
>> Thanks,
>> Tom
>> On 2021-10-20 22:43, Tom MacLean wrote:
>>>
>>> Hi All,
>>> I apologize for being a hack .. despite using MH for almost 20 years,
>>> my perl knowledge is poor.
>>> I'm am trying to programatically make MQTT clones of specific MH
>>> objects by calculating a new name, a suitable MQTT topic name and then
>>> eval'ing the code to create the object and tie it to the original
>>> object:
>>> This code is in a sub that receives the object I am linking to "mh_obj":
>>> eval "$new_obj_name = new mqtt_Item(\$mqtt_1, \"$mqtt_topic\");";
>>> eval "$mh_obj_name->tie_event('sync_mqtt($mh_obj_name, $new_obj_name,0)');";
>>> The first line runs without errors (or visible result). The second
>>> line runs successfully (because the event gets tied), but the
>>> $new_obj_name object isn't visible, I get 'Global symbol
>>> "$Basement_Landing_mqtt" (this is $new_obj_name) requires explicit
>>> package name'. So the tied event code does not see the object I
>>> created in the first eval.
>>> What went wrong? Is my eval scope only that of the sub, and once the
>>> sub ends my created object dies? Is there a way this can work?
>>> Thanks,
>>> Tom
>> ________________________________________________________
>> To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users
> ________________________________________________________
> To unsubscribe from this list, go to:
> https://lists.sourceforge.net/lists/listinfo/misterhouse-users
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users