Commits

Burak Gürsoy committed ea96251

Another fix for sysctl parser

Comments (0)

Files changed (2)

 
 0.7951 Thu May 19 01:13:52 2011
     => Use gmtime for parser tests.
+    => Another fix for sysctl parser.
 
 0.795 Mon May 16 04:09:54 2011
     => Swap support.

lib/Sys/Info/Driver/OSX.pm

     qr{name                    .+? in .+? is \s unknown}xms,
 ;
 use constant RE_SYSCTL_SPLIT   => qr{\n+}xms;
-use constant RE_SYSCTL_ROW     => qr{:(?:\s)+?}xms;
-use constant RE_OLD_SYSCTL_ROW => qr{(?:\s)+?=(?:\s)+?}xms;
+use constant RE_SYSCTL_ROW     => qr{
+    \A
+    ([a-zA-Z0-9_.]+) # this must be capturing parenthesis
+    (?:\s+)?         # optional space
+    [:=]             # the key name termination character
+                     # new sysctl uses ":" to separate key/value pairs
+}xms;
 
 use Capture::Tiny qw( capture );
 use Carp          qw( croak   );
 }
 
 sub _parse_sysctl_row {
-    my($row, $key, $major) = @_;
-    $major ||= do {
-        my %sw_vers = sw_vers();
-        (split m{[.]}xms, $sw_vers{ProductVersion} || q{})[0] || 0;
-    };
-    my $re_row = $major == 10 ? RE_SYSCTL_ROW : RE_OLD_SYSCTL_ROW;
-    my($name, $value) = split $re_row, $row, 2;
-    if ( ! $value && ( ! defined $value || $value ne '0' ) ) {
+    my($row, $key) = @_;
+    my(undef, $name, $value) = split RE_SYSCTL_ROW, $row, 2;
+    if ( ! defined $value || $value eq q{} ) {
         croak sprintf q(Can't happen: No value in output for property )
-                    . q('%s' inside row '%s' collected from key '%s'),
+                     . q('%s' inside row '%s' collected from key '%s'),
                         $name || q([no name]),
                         $row,
                         $key;
     }
-    return $name, $value;
+    return map { __PACKAGE__->trim( $_ ) } $name, $value;
 }
 
 sub _sysctl_not_exists {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.