| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Packages::Dpkg; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 1679 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 7 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 5 | 1 |  |  | 1 |  | 5 | use vars qw($VERSION @ISA); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 678 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Alien::Packages::Dpkg - get's information from Debian's package database via dpkg-query | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =cut | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | $VERSION = "0.003"; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | require Alien::Packages::Base; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | @ISA = qw(Alien::Packages::Base); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =head1 ISA | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | Alien::Packages::Rpm | 
| 22 |  |  |  |  |  |  | ISA Alien::Packages::Base | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =cut | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | require IPC::Cmd; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | my $dpkg_query; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 SUBROUTINES/METHODS | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head2 usable | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Returns true when the C command could be found in the path. | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =cut | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub usable | 
| 39 |  |  |  |  |  |  | { | 
| 40 | 1 | 50 |  | 1 | 1 | 9 | unless ( defined($dpkg_query) ) | 
| 41 |  |  |  |  |  |  | { | 
| 42 | 1 |  |  |  |  | 7 | $dpkg_query = IPC::Cmd::can_run('dpkg-query'); | 
| 43 | 1 |  | 50 |  |  | 113387 | $dpkg_query ||= ''; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 |  |  |  |  | 24 | return $dpkg_query; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head2 list_packages | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | Returns the list of installed I packages. | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | =cut | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub list_packages | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 1 |  |  | 1 | 1 | 2 | my $self = $_[0]; | 
| 58 | 1 |  |  |  |  | 3 | my @packages; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 1 |  |  |  |  | 15 | my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = | 
| 61 |  |  |  |  |  |  | $self->_run_ipc_cmd( | 
| 62 |  |  |  |  |  |  | command => [ $dpkg_query, '-W', q(-f=${Package}:${Version}:${Description}\n) ], | 
| 63 |  |  |  |  |  |  | verbose => 0, ); | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 1 | 50 |  |  |  | 14 | if ($success) | 
| 66 |  |  |  |  |  |  | { | 
| 67 | 1 |  |  |  |  | 143 | chomp $stdout_buf->[0]; | 
| 68 | 1 |  |  |  |  | 1127 | my @pkglist = split( /\n/, $stdout_buf->[0] ); | 
| 69 | 1 |  |  |  |  | 71 | my %pkg_details; | 
| 70 | 1 |  |  |  |  | 8 | foreach my $pkg (@pkglist) | 
| 71 |  |  |  |  |  |  | { | 
| 72 | 1983 | 100 |  |  |  | 3825 | if ( 0 == index( $pkg, ' ' ) ) | 
| 73 |  |  |  |  |  |  | { | 
| 74 | 1719 |  |  |  |  | 8075 | push( @{ $pkg_details{Description} }, $pkg ); | 
|  | 1719 |  |  |  |  | 4316 |  | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | else | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 264 | 100 |  |  |  | 1992 | %pkg_details and push( @packages, {%pkg_details} ); | 
| 79 | 264 |  |  |  |  | 1088 | @pkg_details{ 'Package', 'Version', 'Summary' } = split( ':', $pkg ); | 
| 80 | 264 |  |  |  |  | 736 | $pkg_details{Description} = []; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  | } | 
| 83 | 1 | 50 |  |  |  | 117 | %pkg_details and push( @packages, {%pkg_details} ); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 1 |  |  |  |  | 128 | return @packages; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head2 list_fileowners | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | Returns the I packages which are associated to requested file(s). | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =cut | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | sub list_fileowners | 
| 96 |  |  |  |  |  |  | { | 
| 97 | 1 |  |  | 1 | 1 | 4 | my ( $self, @files ) = @_; | 
| 98 | 1 |  |  |  |  | 3 | my %file_owners; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 1 |  |  |  |  | 6 | foreach my $file (@files) | 
| 101 |  |  |  |  |  |  | { | 
| 102 | 2 |  |  |  |  | 20 | my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = | 
| 103 |  |  |  |  |  |  | $self->_run_ipc_cmd( command => [ $dpkg_query, '-S', $file ], | 
| 104 |  |  |  |  |  |  | verbose => 0, ); | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 2 | 100 |  |  |  | 38 | if ($success) | 
| 107 |  |  |  |  |  |  | { | 
| 108 | 1 |  |  |  |  | 14 | chomp $stdout_buf->[0]; | 
| 109 | 1 |  |  |  |  | 16 | my @pkglist = split( /\n/, $stdout_buf->[0] ); | 
| 110 | 1 |  |  |  |  | 8 | foreach my $pkg (@pkglist) | 
| 111 |  |  |  |  |  |  | { | 
| 112 | 1 | 50 |  |  |  | 31 | if ( my ( $pkg_names, $fn ) = $pkg =~ m/^([^:]+):\s+([^\s].*)$/ ) | 
| 113 |  |  |  |  |  |  | { | 
| 114 | 1 |  |  |  |  | 7 | foreach my $pkg_name (split /\s*,\s*/, $pkg_names) | 
| 115 |  |  |  |  |  |  | { | 
| 116 | 1 |  |  |  |  | 4 | push( @{ $file_owners{$fn} }, { Package => $pkg_name } ); | 
|  | 1 |  |  |  |  | 16 |  | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 1 |  |  |  |  | 19 | return %file_owners; | 
| 124 |  |  |  |  |  |  | } | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head1 AUTHOR | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | Jens Rehsack, C<<  >> | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | Copyright 2010 Jens Rehsack. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 135 |  |  |  |  |  |  | under the terms of either: the GNU General Public License as published | 
| 136 |  |  |  |  |  |  | by the Free Software Foundation; or the Artistic License. | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | See http://dev.perl.org/licenses/ for more information. | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =cut | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | 1; |