| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Packages::Pkg_Info::ports; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 739 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 5 | 1 |  |  | 1 |  | 4 | use vars qw($VERSION @ISA); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 675 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Alien::Packages::Pkg_Info::ports - deals with FreeBSD's Ports | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =cut | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | $VERSION = "0.001"; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | require Alien::Packages::Base; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | @ISA = qw(Alien::Packages::Base); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =head1 ISA | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | Alien::Packages::Pkg_Info::ports | 
| 22 |  |  |  |  |  |  | ISA Alien::Packages::Base | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =cut | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | require IPC::Cmd; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =head1 SUBROUTINES/METHODS | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head2 usable | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | Returns true, when the command C could be found in the path and | 
| 33 |  |  |  |  |  |  | C returns a valid release date. | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =cut | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | my $pkg_info; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub usable | 
| 40 |  |  |  |  |  |  | { | 
| 41 | 1 | 50 |  | 1 | 1 | 5 | unless ( defined($pkg_info) ) | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 1 |  |  |  |  | 3 | my @pkg_info; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 1 |  |  |  |  | 1 | local $@; | 
| 46 | 1 |  |  |  |  | 2 | eval { | 
| 47 | 1 |  |  |  |  | 6 | require File::Which; | 
| 48 | 1 |  |  |  |  | 5 | @pkg_info = File::Which::where('pkg_info'); | 
| 49 |  |  |  |  |  |  | }; | 
| 50 | 1 | 50 |  |  |  | 101 | if ($@) | 
| 51 |  |  |  |  |  |  | { | 
| 52 | 0 |  |  |  |  | 0 | @pkg_info = grep { $_ } ( IPC::Cmd::can_run('pkg_info') ); | 
|  | 0 |  |  |  |  | 0 |  | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 1 |  |  |  |  | 2 | foreach my $piexe (@pkg_info) | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 0 |  |  |  |  | 0 | my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = | 
| 58 |  |  |  |  |  |  | IPC::Cmd::run( command => [ $piexe, '-qP' ], | 
| 59 |  |  |  |  |  |  | verbose => 0, ); | 
| 60 | 0 |  | 0 |  |  | 0 | my $ports = $success && @{$stdout_buf} && $stdout_buf->[0] =~ m/^\d{4}\d{2}\d{2}$/; | 
| 61 | 0 | 0 | 0 |  |  | 0 | $ports and $pkg_info = $piexe and last; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 1 | 50 |  |  |  | 4 | defined($pkg_info) or $pkg_info = ''; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 1 |  |  |  |  | 4 | return $pkg_info; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head2 list_packages | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | Returns the list of installed FreeBSD ports. | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =cut | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub list_packages | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 0 |  |  | 0 | 1 |  | my $self = $_[0]; | 
| 79 | 0 |  |  |  |  |  | my @packages; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 0 |  |  |  |  |  | my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = | 
| 82 |  |  |  |  |  |  | $self->_run_ipc_cmd( command => [$pkg_info], | 
| 83 |  |  |  |  |  |  | verbose => 0, ); | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 0 | 0 |  |  |  |  | if ($success) | 
| 86 |  |  |  |  |  |  | { | 
| 87 | 0 |  |  |  |  |  | my @pkglist = split( /\n/, $stdout_buf->[0] ); | 
| 88 | 0 |  |  |  |  |  | foreach my $pkg (@pkglist) | 
| 89 |  |  |  |  |  |  | { | 
| 90 | 0 |  |  |  |  |  | my @pkg_details = split( ' ', $pkg, 2 ); | 
| 91 | 0 | 0 |  |  |  |  | if ( $pkg_details[0] =~ m/^(.*)-([^-]*)$/ ) | 
| 92 |  |  |  |  |  |  | { | 
| 93 | 0 |  |  |  |  |  | push( | 
| 94 |  |  |  |  |  |  | @packages, | 
| 95 |  |  |  |  |  |  | { | 
| 96 |  |  |  |  |  |  | Package => $1, | 
| 97 |  |  |  |  |  |  | Version => $2, | 
| 98 |  |  |  |  |  |  | Summary => $pkg_details[1] | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  | ); | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 0 |  |  |  |  |  | return @packages; | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =head2 list_fileowners | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | Returns the names of the ports which have installed the requested files. | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =cut | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | sub list_fileowners | 
| 115 |  |  |  |  |  |  | { | 
| 116 | 0 |  |  | 0 | 1 |  | my ( $self, @files ) = @_; | 
| 117 | 0 |  |  |  |  |  | my %file_owners; | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  |  |  |  | foreach my $file (@files) | 
| 120 |  |  |  |  |  |  | { | 
| 121 | 0 |  |  |  |  |  | my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = | 
| 122 |  |  |  |  |  |  | $self->_run_ipc_cmd( command => [ $pkg_info, '-q', '-W', $file ], | 
| 123 |  |  |  |  |  |  | verbose => 0, ); | 
| 124 |  |  |  |  |  |  |  | 
| 125 | 0 | 0 |  |  |  |  | if ($success) | 
| 126 |  |  |  |  |  |  | { | 
| 127 | 0 |  |  |  |  |  | chomp $stdout_buf->[0]; | 
| 128 | 0 | 0 |  |  |  |  | if ( $stdout_buf->[0] =~ m/^(.*)-([^-]*)$/ ) | 
| 129 |  |  |  |  |  |  | { | 
| 130 | 0 |  |  |  |  |  | push( @{ $file_owners{$file} }, { Package => $1 } ); | 
|  | 0 |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 0 |  |  |  |  |  | return %file_owners; | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =head1 AUTHOR | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | Jens Rehsack, C<<  >> | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | Copyright 2010 Jens Rehsack. | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 147 |  |  |  |  |  |  | under the terms of either: the GNU General Public License as published | 
| 148 |  |  |  |  |  |  | by the Free Software Foundation; or the Artistic License. | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | See http://dev.perl.org/licenses/ for more information. | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =cut | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | 1; |