Hello community,

here is the log from the commit of package perl-Linux-DesktopFiles for 
openSUSE:Factory checked in at 2017-10-23 16:52:06
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Linux-DesktopFiles (Old)
 and      /work/SRC/openSUSE:Factory/.perl-Linux-DesktopFiles.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "perl-Linux-DesktopFiles"

Mon Oct 23 16:52:06 2017 rev:3 rq:535745 version:0.24

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/perl-Linux-DesktopFiles/perl-Linux-DesktopFiles.changes
  2017-10-06 11:04:01.900068892 +0200
+++ 
/work/SRC/openSUSE:Factory/.perl-Linux-DesktopFiles.new/perl-Linux-DesktopFiles.changes
     2017-10-23 16:52:36.006627148 +0200
@@ -1,0 +2,13 @@
+Sun Oct 22 05:28:09 UTC 2017 - [email protected]
+
+- updated to 0.24
+   see /usr/share/doc/packages/perl-Linux-DesktopFiles/Changes
+
+  0.24  2017-10-21
+      - When `keep_unknown_categories` is true and a given entry does not 
belong to any category, `parse_desktop_file` will set `Categories` to 
[`unknown_category_key`].
+  
+  0.23  2017-10-21
+      - Escaped strings are now unescaped.
+      - Added the `parse_desktop_file` method, which parses a single desktop 
file.
+
+-------------------------------------------------------------------

Old:
----
  Linux-DesktopFiles-0.22.tar.gz

New:
----
  Linux-DesktopFiles-0.24.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ perl-Linux-DesktopFiles.spec ++++++
--- /var/tmp/diff_new_pack.Oc1xkR/_old  2017-10-23 16:52:36.790590458 +0200
+++ /var/tmp/diff_new_pack.Oc1xkR/_new  2017-10-23 16:52:36.790590458 +0200
@@ -17,7 +17,7 @@
 
 
 Name:           perl-Linux-DesktopFiles
-Version:        0.22
+Version:        0.24
 Release:        0
 %define cpan_name Linux-DesktopFiles
 Summary:        Fast parsing of the Linux desktop files

++++++ Linux-DesktopFiles-0.22.tar.gz -> Linux-DesktopFiles-0.24.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Linux-DesktopFiles-0.22/Changes 
new/Linux-DesktopFiles-0.24/Changes
--- old/Linux-DesktopFiles-0.22/Changes 2017-10-04 21:38:18.000000000 +0200
+++ new/Linux-DesktopFiles-0.24/Changes 2017-10-21 18:39:47.000000000 +0200
@@ -1,5 +1,12 @@
 Revision history for Perl extension Linux::DesktopFiles.
 
+0.24  2017-10-21
+    - When `keep_unknown_categories` is true and a given entry does not belong 
to any category, `parse_desktop_file` will set `Categories` to 
[`unknown_category_key`].
+
+0.23  2017-10-21
+    - Escaped strings are now unescaped.
+    - Added the `parse_desktop_file` method, which parses a single desktop 
file.
+
 0.22  2017-10-04
     - Make sure the category names are unique, so we don't store an 
application twice under the same category.
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Linux-DesktopFiles-0.22/META.json 
new/Linux-DesktopFiles-0.24/META.json
--- old/Linux-DesktopFiles-0.22/META.json       2017-10-04 21:38:18.000000000 
+0200
+++ new/Linux-DesktopFiles-0.24/META.json       2017-10-21 18:39:47.000000000 
+0200
@@ -28,7 +28,7 @@
    "provides" : {
       "Linux::DesktopFiles" : {
          "file" : "lib/Linux/DesktopFiles.pm",
-         "version" : "0.22"
+         "version" : "0.24"
       }
    },
    "release_status" : "stable",
@@ -44,6 +44,6 @@
          "url" : "https://github.com/trizen/Linux-DesktopFiles";
       }
    },
-   "version" : "0.22",
+   "version" : "0.24",
    "x_serialization_backend" : "JSON::PP version 2.94"
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Linux-DesktopFiles-0.22/META.yml 
new/Linux-DesktopFiles-0.24/META.yml
--- old/Linux-DesktopFiles-0.22/META.yml        2017-10-04 21:38:18.000000000 
+0200
+++ new/Linux-DesktopFiles-0.24/META.yml        2017-10-21 18:39:47.000000000 
+0200
@@ -15,7 +15,7 @@
 provides:
   Linux::DesktopFiles:
     file: lib/Linux/DesktopFiles.pm
-    version: '0.22'
+    version: '0.24'
 requires:
   perl: '5.014'
 resources:
@@ -23,5 +23,5 @@
   homepage: https://github.com/trizen/Linux-DesktopFiles
   license: http://opensource.org/licenses/artistic-license-2.0.php
   repository: https://github.com/trizen/Linux-DesktopFiles
-version: '0.22'
+version: '0.24'
 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Linux-DesktopFiles-0.22/lib/Linux/DesktopFiles.pm 
new/Linux-DesktopFiles-0.24/lib/Linux/DesktopFiles.pm
--- old/Linux-DesktopFiles-0.22/lib/Linux/DesktopFiles.pm       2017-10-04 
21:38:18.000000000 +0200
+++ new/Linux-DesktopFiles-0.24/lib/Linux/DesktopFiles.pm       2017-10-21 
18:39:47.000000000 +0200
@@ -9,7 +9,7 @@
 #use strict;
 #use warnings;
 
-our $VERSION = '0.22';
+our $VERSION = '0.24';
 
 our %TRUE_VALUES = (
                     'true' => 1,
@@ -22,7 +22,7 @@
 
     my %data = (
         keep_unknown_categories => 0,
-        unknown_category_key    => 'other',
+        unknown_category_key    => 'Other',
 
         case_insensitive_cats => 0,
 
@@ -107,69 +107,70 @@
     wantarray ? values(%table) : [values(%table)];
 }
 
-sub parse {
-    my ($self, $file_data, @desktop_files) = @_;
+# Used for unescaping strings
+my %Chr = (s => ' ', n => "\n", r => "\r", t => "\t", '\\' => '\\');
 
-    foreach my $desktop_file (@desktop_files) {
+sub parse_desktop_file {
+    my ($self, $desktop_file) = @_;
 
-        # Check the filename and skip it if it matches `skip_filename_re`
-        if (defined $self->{skip_filename_re}) {
-            substr($desktop_file, rindex($desktop_file, '/') + 1) =~ 
/$self->{skip_filename_re}/ && next;
-        }
+    # Check the filename and skip it if it matches `skip_filename_re`
+    if (defined $self->{skip_filename_re}) {
+        substr($desktop_file, rindex($desktop_file, '/') + 1) =~ 
/$self->{skip_filename_re}/ && return;
+    }
 
-        # Open and read the desktop file
-        sysopen my $desktop_fh, $desktop_file, 0 or next;
-        sysread $desktop_fh, (my $file), -s $desktop_file;
-
-        # Locate the "[Desktop Entry]" section
-        if ((my $index = index($file, "]\n", index($file, "[Desktop Entry]") + 
15)) != -1) {
-            $file = substr($file, 0, $index);
-        }
+    # Open and read the desktop file
+    sysopen my $desktop_fh, $desktop_file, 0 or return;
+    sysread $desktop_fh, (my $file), -s $desktop_file;
+
+    # Locate the "[Desktop Entry]" section
+    if ((my $index = index($file, "]\n", index($file, "[Desktop Entry]") + 
15)) != -1) {
+        $file = substr($file, 0, $index);
+    }
 
-        # Parse the entry data
-        my %info = $file =~ /$self->{_file_keys_re}/g;
+    # Parse the entry data
+    my %info = $file =~ /$self->{_file_keys_re}/g;
 
-        # Ignore the file when `NoDisplay` is true
-        if (exists $info{NoDisplay}) {
-            next if exists $TRUE_VALUES{$info{NoDisplay}};
-        }
+    # Ignore the file when `NoDisplay` is true
+    if (exists $info{NoDisplay}) {
+        return if exists $TRUE_VALUES{$info{NoDisplay}};
+    }
 
-        # Ignore the file when `Hidden` is true
-        if (exists $info{Hidden}) {
-            next if exists $TRUE_VALUES{$info{Hidden}};
-        }
+    # Ignore the file when `Hidden` is true
+    if (exists $info{Hidden}) {
+        return if exists $TRUE_VALUES{$info{Hidden}};
+    }
 
-        # If no 'Name' entry is defined, create one with the name of the file
-        $info{Name} //= substr($desktop_file, rindex($desktop_file, '/') + 1, 
-8);
+    # If no 'Name' entry is defined, create one with the name of the file
+    $info{Name} //= substr($desktop_file, rindex($desktop_file, '/') + 1, -8);
 
-        # Handle `skip_entry`
-        if (defined($self->{skip_entry}) and ref($self->{skip_entry}) eq 
'ARRAY') {
-            my $skip;
-            foreach my $pair_ref (@{$self->{skip_entry}}) {
-                if (exists($info{$pair_ref->{key}}) and 
$info{$pair_ref->{key}} =~ /$pair_ref->{re}/) {
-                    $skip = 1;
-                    last;
-                }
+    # Unescape string escapes (\n, \t, etc.)
+    $info{$_} =~ s{\\(.)}{ $Chr{$1} // $1 }eg for (keys %info);
+
+    # Handle `skip_entry`
+    if (defined($self->{skip_entry}) and ref($self->{skip_entry}) eq 'ARRAY') {
+        foreach my $pair_ref (@{$self->{skip_entry}}) {
+            if (exists($info{$pair_ref->{key}}) and $info{$pair_ref->{key}} =~ 
/$pair_ref->{re}/) {
+                return;
             }
-            $skip and next;
         }
+    }
 
-        # Make user-defined substitutions
-        if (defined($self->{substitutions}) and ref($self->{substitutions}) eq 
'ARRAY') {
-            foreach my $pair_ref (@{$self->{substitutions}}) {
-                if (exists $info{$pair_ref->{key}}) {
-                    if ($pair_ref->{global}) {
-                        $info{$pair_ref->{key}} =~ 
s/$pair_ref->{re}/$pair_ref->{value}/g;
-                    }
-                    else {
-                        $info{$pair_ref->{key}} =~ 
s/$pair_ref->{re}/$pair_ref->{value}/;
-                    }
+    # Make user-defined substitutions
+    if (defined($self->{substitutions}) and ref($self->{substitutions}) eq 
'ARRAY') {
+        foreach my $pair_ref (@{$self->{substitutions}}) {
+            if (exists $info{$pair_ref->{key}}) {
+                if ($pair_ref->{global}) {
+                    $info{$pair_ref->{key}} =~ 
s/$pair_ref->{re}/$pair_ref->{value}/g;
+                }
+                else {
+                    $info{$pair_ref->{key}} =~ 
s/$pair_ref->{re}/$pair_ref->{value}/;
                 }
             }
         }
+    }
 
-        # Parse categories (and remove any duplicates)
-        my %categories;
+    # Parse categories (and remove any duplicates)
+    my %categories;
 
 #<<<
         @categories{
@@ -181,50 +182,67 @@
         } = ();
 #>>>
 
-        # Skip entry when there are no categories and 
`keep_unknown_categories` is false
-        scalar(%categories) or $self->{keep_unknown_categories} or next;
+    my @cats = keys %categories;
 
-        # Remove `% ...` from the value of `Exec`
-        index($info{Exec}, ' %') != -1 and $info{Exec} =~ s/ +%.*//s;
-
-        # Terminalize
-        if (    $self->{terminalize}
-            and defined($info{Terminal})
-            and exists($TRUE_VALUES{$info{Terminal}})) {
-            $info{Exec} = sprintf($self->{terminalization_format}, 
$self->{terminal}, $info{Exec});
+    # Skip entry when there are no categories and `keep_unknown_categories` is 
false
+    # When `keep_unknown_categories` is true, set `@cats` to 
`unknown_category_key`.
+    if (!@cats) {
+        if ($self->{keep_unknown_categories}) {
+            push @cats, $self->{unknown_category_key};
+        }
+        else {
+            return;
         }
+    }
 
-        # Check and clean the icon name
-        if (exists $info{Icon}) {
-            my $icon = $info{Icon};
-
-            my $abs;
-            if (substr($icon, 0, 1) eq '/') {
-                if (-f $icon) {    # icon is specified as an absolute path
-                    $abs = 1;
-                }
-                else {             # ... otherwise, take its basename
-                    $icon = substr($icon, 1 + rindex($icon, '/'));
-                }
-            }
+    # Store the categories
+    $info{Categories} = \@cats;
+
+    # Remove `% ...` from the value of `Exec`
+    index($info{Exec}, ' %') != -1 and $info{Exec} =~ s/ +%.*//s;
+
+    # Terminalize
+    if (    $self->{terminalize}
+        and defined($info{Terminal})
+        and exists($TRUE_VALUES{$info{Terminal}})) {
+        $info{Exec} = sprintf($self->{terminalization_format}, 
$self->{terminal}, $info{Exec});
+    }
 
-            # Remove any icon extension
-            if (!$abs) {
-                $icon =~ s/\.(?:png|jpe?g|svg|xpm)\z//i;
+    # Check and clean the icon name
+    if (exists $info{Icon}) {
+        my $icon = $info{Icon};
+
+        my $abs;
+        if (substr($icon, 0, 1) eq '/') {
+            if (-f $icon) {    # icon is specified as an absolute path
+                $abs = 1;
             }
+            else {             # otherwise, take its basename
+                $icon = substr($icon, 1 + rindex($icon, '/'));
+            }
+        }
 
-            # Store the icon back into `%info`
-            $info{Icon} = $icon;
+        # Remove any icon extension
+        if (!$abs) {
+            $icon =~ s/\.(?:png|jpe?g|svg|xpm)\z//i;
         }
 
+        # Store the icon back into `%info`
+        $info{Icon} = $icon;
+    }
+
+    return %info;
+}
+
+sub parse {
+    my ($self, $hash_ref, @desktop_files) = @_;
+
+    foreach my $desktop_file (@desktop_files) {
+        (my %info = $self->parse_desktop_file($desktop_file)) || next;
+
         # Push the entry into its belonging categories
-        if (scalar(%categories)) {
-            foreach my $category (keys %categories) {
-                push @{$file_data->{$category}}, {map { $_ => $info{$_} } 
@{$self->{keys_to_keep}}};
-            }
-        }
-        elsif ($self->{keep_unknown_categories}) {
-            push @{$file_data->{$self->{unknown_category_key}}}, {map { $_ => 
$info{$_} } @{$self->{keys_to_keep}}};
+        foreach my $category (@{$info{Categories}}) {
+            push @{$hash_ref->{$category}}, \%info;
         }
     }
 }
@@ -304,7 +322,7 @@
         case_insensitive_cats   => 0,
 
         keep_unknown_categories => 0,
-        unknown_category_key    => 'other',
+        unknown_category_key    => 'Other',
       );
 
 =back
@@ -319,8 +337,7 @@
 
 =item keys_to_keep => [qw(Name Exec Icon Comment ...)]
 
-Any valid keys from the desktop files. This keys will be stored in the returned
-hash reference when calling C<$obj-E<gt>parse_desktop_files>.
+Any valid keys from the desktop files to keep in the results from 
C<parse_desktop_file>. The B<Categories> option is implicitly included.
 
 =item categories => [qw(Graphics Network AudioVideo ...)]
 
@@ -358,6 +375,8 @@
 
     terminal -e 'command'
 
+This option will include the C<Terminal> key inside the B<keys_to_keep> array.
+
 =item terminalization_format => q{%s -e '%s'}
 
 Format used by C<sprintf()> to terminalize a command which requires to be 
executed
@@ -393,10 +412,13 @@
 =item substitutions => [{key => 'KeyName', re => qr/REGEX/i, value => 
'Value'}, {...}]
 
 Substitute, by using a regex, in the values of the desktop files.
+
 The B<key> can be any valid key from the desktop files.
+
 The B<re> can be any valid regular expression. Anything matched by the regex, 
will be
 replaced the string stored in B<value>.
-For global matching/substitution, you need to set the B<global> key to a true 
value.
+
+For global matching/substitution, set the B<global> key to a true value.
 
 Example:
 
@@ -418,19 +440,40 @@
 
 =item $obj->parse(\%hash, @desktop_files)
 
-Parse a list of desktop files into a HASH ref.
+Parse a list of desktop files into a HASH ref, where the keys of the HASH are
+the categories from desktop files.
+
+=item $obj->parse_desktop_file($desktop_file)
+
+Parse a given desktop file and return a key-value list as a result.
+
+Example:
+
+    my %info = $obj->parse_desktop_file($desktop_file);
+
+where C<%info> might look something like this:
+
+    my %info = (
+        Name       => "...",
+        Exec       => "...",
+        Icon       => "...",
+        Categories => ["...", "...", "..."],
+    );
+
+When B<keep_unknown_categories> is true and a given entry does not belong to 
any category,
+C<parse_desktop_file> will set B<Categories> to [C<unknown_category_key>].
 
 =item $obj->parse_desktop_files()
 
-It returns a HASH reference which categories names as keys, and ARRAY 
references
-as values which contains HASH references with the keys specified in the 
B<keys_to_keep>
+It returns a HASH reference categorized on category names, with ARRAY 
references
+as values, each ARRAY containing a HASH reference with the keys specified in 
the B<keys_to_keep>
 option, and values from the desktop files.
 
 The returned HASH reference might look something like this:
 
         {
-          utility => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => 
"..."} ],
-          network => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => 
"..."} ],
+          Utility => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => 
"..."} ],
+          Network => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => 
"..."} ],
         }
 
 This function is equivalent with:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Linux-DesktopFiles-0.22/t/Linux-DesktopFiles.t 
new/Linux-DesktopFiles-0.24/t/Linux-DesktopFiles.t
--- old/Linux-DesktopFiles-0.22/t/Linux-DesktopFiles.t  2017-10-04 
21:38:18.000000000 +0200
+++ new/Linux-DesktopFiles-0.24/t/Linux-DesktopFiles.t  2017-10-21 
18:39:47.000000000 +0200
@@ -5,29 +5,34 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 BEGIN { use_ok('Linux::DesktopFiles') }
 
 #########################
 
 my $obj = Linux::DesktopFiles->new(
-                                   keys_to_keep              => [qw(Name 
GenericName Comment Comment[ro] Terminal Icon Exec)],
-                                   categories                => [qw(Game 
Archiving)],
-                                  );
+        keys_to_keep => [qw(Name GenericName Comment Comment[ro] Terminal Icon 
Exec)],
+        categories   => [qw(Game Archiving)],
+);
 
 my $t_file = 't/file.desktop';
-$obj->parse(\my %hash, (-f $t_file) ? $t_file : (-f $0) ? 'file.desktop' : ());
+my $desktop_file = (-f $t_file) ? $t_file : (-f $0) ? 'file.desktop' : ();
+
+$obj->parse(\my %hash, $desktop_file);
 
 my $info = $hash{Archiving}[0];
 
-ok($info->{Name}          eq "The right name",          "Name");
-ok($info->{GenericName}   eq "Also this name is right", "GenericName");
-ok($info->{Exec}          eq "some_command -z -9",      "Exec");
-ok($info->{Comment}       eq "This is a test!",         "Comment");
-ok($info->{'Comment[ro]'} eq "Acesta este un test!",    "Comment[ro]");
-ok($info->{Terminal}      eq "true",                    "Terminal");
-ok($info->{Icon}          eq "icon_name",               "Icon");
-
-# Not defined
-ok(!defined($info->{Categories}), "Categories");
-ok(!defined($info->{Encoding}),   "Encoding");
+ok($info->{Name} eq "The right name",                 "Name");
+ok($info->{GenericName} eq "Also this name is right", "GenericName");
+ok($info->{Exec} eq "some_command -z -9",             "Exec");
+ok($info->{Comment} eq "This is a test!",             "Comment");
+ok($info->{'Comment[ro]'} eq "Acesta este un test!",  "Comment[ro]");
+ok($info->{Terminal} eq "true",                       "Terminal");
+ok($info->{Icon} eq "icon_name",                      "Icon");
+
+my %entry = $obj->parse_desktop_file($desktop_file);
+
+is($entry{Name},     'The right name',     'Name');
+is($entry{Exec},     'some_command -z -9', 'Exec');
+is($entry{Terminal}, 'true',               'Terminal');
+is($entry{Icon},     'icon_name',          'Icon');


Reply via email to