[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-Modules] Glue



At 7:41 -0400 1999.09.14, Dave Johnson wrote:
>#!perl -wl
>use Mac::Glue ':all';
>use strict;
>
>my($p, %params, $params);
>$p = new Mac::Glue 'Finder';
># Get status of PPP
>%params = $p->ppp_status();
>print  $params{'RAsb'};
>
>I get the feeling I am missing something and there is a cooler way such as:
>
>print $p->prop('state', of => $p->ppp_status());  # does not work
>
>Can someone show me where I went worng?

Well, in AppleScript it would be something like this:

    get state of (PPP status)

That is, you need to evaluate PPP status and then get the state key.  You
can't just do "get state of PPP status" in AppleScript.  So it is similar
here:

    print ${{$p->ppp_status}}{RAsb};  # ref to hash, deref, get value

Or as you did it, put it into a real hash, and then get the value.

Note I am planning on allowing this instead (or maybe in addition to?):

    print ${{$p->ppp_status}}{state};

But I first need to figure out exactly how to do it.  It shouldn't be too
difficult ... I believe it should be the case that every key to the record
should be a class/property name.  Any thoughts or insights?

Here is another problem: should $p->ppp_status return a hash, a hashref, or
differently depending on list or scalar context?  If don't like the latter
option, but I thought I would mention it.  :)  But if it returned a hash
reference instead of a hash, the advantages would be:

  1.  Nicer abbreivated syntax:  $p->ppp_status->{state}
  2.  Lower memory requirements if a big record is returned (not likely with
      Apple events)

Disadvantages:

  1.  Must assign my $hash = $p->ppp_status, and then call $hash->{key}
      instead of my %hash = $p->ppp_status, $hash{key}; breaks old code
      and is more effort to use in some cases (two extra chracters to type!)

There are probably more.  Any suggestions?

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-modules-request@macperl.org