Re: More JSON handling routines in LMS builds?
Paul Webster <Paul.Webster.aer8on-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]>
| Newsgroups | gmane.music.equipment.slimdevices.devel |
|---|---|
| Organization | Logitech Squeezebox Forums |
| Message-ID | <[email protected]> |
I would like to replace lots of bits of code that are variants on
Code:
--------------------
if (ref($perl_data) ne "ARRAY" &&
exists $perl_data->{"data"} &&
exists $perl_data->{"data"}->{"TitleDiffusions"} && ref($perl_data->{"data"}->{"TitleDiffusions"}) eq "ARRAY" )
--------------------
with something in my config file that results in something like
my @paths = [ '$root/TitleDiffusions[0]' ];
Then the if statement becomes something like ...
Code:
--------------------
my $matched = true;
foreach my $path ( @paths ){
my $jpath = JSON::Path->new($path);
$matched = false if $jpath == 0;
}
if ( $matched ){
// process it
etc
etc
}
--------------------
Another "if" looks like this ...
Code:
--------------------
if (ref($perl_data) ne "ARRAY" &&
exists $perl_data->{"id_playlst"} && exists $perl_data->{"update_tm"} &&
exists $perl_data->{"itms"} && ref($perl_data->{"itms"}) eq "ARRAY" )
--------------------
which would become
Code:
--------------------
$paths = [
'$root/id_playlst',
'$root/update_tm',
'$root/itms[0]',
];
--------------------
Paul Webster
author of \"now playing\" plugins covering radio france (fip etc),
planetradio (bauer - kiss, absolute, scala, jazzfm etc), kcrw, abc
australia and cbc/radio-canada
and, via the extra \"radio now playing\" plugin lots more - see
https://forums.slimdevices.com/showthread.php?115201-announce-radio-now-playing-plugin
------------------------------------------------------------------------
Paul Webster's Profile: http://forums.slimdevices.com/member.php?userid=105
View this thread: http://forums.slimdevices.com/showthread.php?t=115821