Skip Menu |

This queue is for tickets about the Mac-PropertyList CPAN distribution.

Report information
The Basics
Id: 75240
Status: resolved
Priority: 0/
Queue: Mac-PropertyList

People
Owner: Nobody in particular
Requestors: jgrg [...] sanger.ac.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Suggested code: perlify_plist()
Date: Thu, 23 Feb 2012 12:02:14 +0000
To: bug-Mac-PropertyList [...] rt.cpan.org
From: James Gilbert <jgrg [...] sanger.ac.uk>
Hi Brian, I just used Mac::PropertyList (I was using 1.33_02) to write some code which sets http_proxy, ftp_proxy etc... in %ENV, based on the current network config found in: /Library/Preferences/SystemConfiguration/preferences.plist Needing to navigate the parsed data, I though plist_as_perl() sounded like what I wanted, but it wasn't useful. So I wrote the appended code, which I thought you might like to include, or something with similar functionality. Thanks for writing Mac::PropertyList, James # Takes a Mac::PropertyList data structure and coverts its objects into a # (more easily usable) plain perl datastructure. sub perlify_plist { my ($item) = @_; if ($item->type eq 'dict') { my $hash = {$item->value}; while (my ($key, $val) = each %$hash) { $hash->{$key} = perlify_plist($val); } return $hash; } elsif ($item->type eq 'array') { my $array = []; foreach my $val ($item->value) { push(@$array, perlify_plist($val)); } return $array; } else { return $item->value; } } -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.
I think the as_perl methods already do this.
Subject: Re: [rt.cpan.org #75240] Suggested code: perlify_plist()
Date: Tue, 6 Mar 2012 15:16:52 +0000
To: bug-Mac-PropertyList [...] rt.cpan.org
From: James Gilbert <jgrg [...] sanger.ac.uk>
On 6 Mar 2012, at 04:21, brian d foy via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=75240 > > > I think the as_perl methods already do this.
Ah, thanks. Yes, the as_perl object methods do this, and do exactly what I want, thanks, but aren't in the POD. The one mentioned in the POD is: Show quoted text
> =item plist_as_perl > > Return the plist data structure as an unblessed Perl data structure. > There won't be any C<Mac::PropertyList> objects in the results. > > =cut > > sub plist_as_perl > { > my $object = CORE::shift; > > my $string = '$VAR = '; > > $string .= $object->as_perl; > > return $string; > }
which isn't any use. James -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE.