/[pxelator]/lib/PXElator/shell.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/PXElator/shell.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 482 - (hide annotations)
Sat Jan 23 18:31:14 2010 UTC (14 years, 3 months ago) by dpavlin
File size: 882 byte(s)
use store::audit proxy all over the place

1 dpavlin 204 package shell;
2    
3     use warnings;
4     use strict;
5    
6     use autodie;
7     use Data::Dump qw/dump/;
8 dpavlin 482 use store;
9 dpavlin 204
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 dpavlin 482 store::audit( $command, $k, $hash );
51 dpavlin 204 } 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;

  ViewVC Help
Powered by ViewVC 1.1.26