Burak Gürsoy avatar Burak Gürsoy committed f2ec066

add more array initialization checks and some cosmetic changes.

Comments (0)

Files changed (1)

lib/Parse/HTTP/UserAgent/Base/Parsers.pm

         return;
     }
 
-    $self->_parse_msie($moz, [ undef, @buf ], undef, split RE_WHITESPACE, $msie);
+    $self->_parse_msie(
+        $moz, [ undef, @buf ], undef, split RE_WHITESPACE, $msie
+    );
 
     my(undef, $mv) = split RE_WHITESPACE, $maxthon;
     my $v = $mv      ? $mv
     (undef, $version)       = split RE_SLASH, $version;
     $self->[UA_NAME]        = $ep ? 'Epiphany' : 'Safari';
     $self->[UA_VERSION_RAW] = $version;
-    $self->[UA_TOOLKIT]     = [ split RE_SLASH, $extra->[0] ];
+    $self->[UA_TOOLKIT]     = $extra ? [ split RE_SLASH, $extra->[0] ] : [];
     $self->[UA_LANG]        = pop @{ $thing };
     $self->[UA_OS]          = @{$thing} && length $thing->[LAST_ELEMENT] > 1
                             ? pop   @{ $thing }
 sub _parse_opera_pre {
     # opera 5,9
     my($self, $moz, $thing, $extra) = @_;
+    my $ffaker = @{$thing} && index($thing->[LAST_ELEMENT], 'rv:') != NO_IMATCH
+               ? pop @{$thing}
+               : 0;
     my($name, $version)     = split RE_SLASH, $moz;
-    my $faking_ff           = @{$thing} && index($thing->[LAST_ELEMENT], 'rv:') != NO_IMATCH
-                            ? pop @{$thing}
-                            : 0
-                            ;
     $self->[UA_NAME]        = $name;
     $self->[UA_VERSION_RAW] = $version;
-    my $ver = $self->_numify( $version );
     my $lang;
 
     if ( $extra ) {
+        # opera changed version string to workaround lame browser sniffers
         # http://dev.opera.com/articles/view/opera-ua-string-changes/
-        my $swap = @{$extra} && index($extra->[LAST_ELEMENT], 'Version/') != NO_IMATCH; # damned 10.0 beta
+        my $swap = @{$extra}
+                   && index($extra->[LAST_ELEMENT], 'Version/') != NO_IMATCH;
         ($lang = $swap ? shift @{$extra} : pop @{$extra}) =~ tr/[]//d;
         if ( $swap ) {
             my $vjunk = pop @{$extra};
         }
     }
 
-    $lang ||= pop @{$thing} if $faking_ff;
+    $lang ||= pop @{$thing} if $ffaker;
 
-    if ( ! $self->[UA_TOOLKIT] && $ver >= OPERA9 && $lang && length( $lang ) > OPERA_TK_LENGTH ) {
+    my $tk_parsed_as_lang = ! $self->[UA_TOOLKIT]
+                            && $self->_numify( $version ) >= OPERA9
+                            && $lang
+                            && length( $lang ) > OPERA_TK_LENGTH;
+
+    if ( $tk_parsed_as_lang ) {
         $self->[UA_TOOLKIT] = [ split RE_SLASH, $lang ];
        ($lang = pop @{$thing}) =~ tr/[]//d if $extra;
     }
                              :                                       $moz
                              ;
     $self->[UA_NAME]         = $name;
-    $self->[UA_TOOLKIT]      = [ split RE_SLASH, $extra->[0] ];
+    $self->[UA_TOOLKIT]      = $extra ? [ split RE_SLASH, $extra->[0] ] : [];
     $self->[UA_VERSION_RAW]  = $version;
 
     if ( @{$thing} && index($thing->[LAST_ELEMENT], 'rv:') != NO_IMATCH ) {
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.