return iso path
[pxelator] / lib / PXElator / shell.pm
1 package shell;
2
3 use warnings;
4 use strict;
5
6 use autodie;
7 use Data::Dump qw/dump/;
8 use store;
9
10 our $command;
11
12 sub command {
13         ( undef, $command ) = @_;
14         __PACKAGE__;
15 }
16
17 sub lines {
18         my ( $self, $key ) = @_;
19
20 warn "command $command key $key";
21
22         my $info;
23
24         my @header;
25
26         my $split_re;
27
28         open(my $brctl, '-|', $command);
29         while(<$brctl>) {
30                 chomp;
31
32                 if ( ! $split_re ) {
33                         $split_re = qr/\t+/ if m/\t/;
34                         $split_re ||= qr/\s+/ if m/\s/;
35                 }
36
37                 my @cols = split( $split_re, $_);
38
39                 if ( ! @header ) {
40                         @header = @cols;
41                         $info->{_header} = [ @header ] if $key;
42                         next;
43                 }
44
45                 my $hash =  { map { ( $header[$_] => $cols[$_] ) } 0 .. $#cols } ;
46
47                 if ( $key ) {
48                         my $k = $cols[$key - 1];
49                         $info->{$k} = $hash;
50                         store::audit( $command, $k, $hash );
51                 } else {
52                         push @$info, $hash;
53                 }
54
55         }
56
57         warn $command, ' ', dump( $info );
58
59         return $info;
60 }
61
62 sub hash_by { lines(@_) }
63
64 1;