/[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 207 - (hide annotations)
Wed Aug 12 22:56:45 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 886 byte(s)
first verision which boots virtual machine logging using new CouchDB::audit code

it need some more work to make it less ugly (especially console output) and
less redundant/useful, but it's a start

1 dpavlin 204 package shell;
2    
3     use warnings;
4     use strict;
5    
6     use autodie;
7     use Data::Dump qw/dump/;
8 dpavlin 207 use CouchDB;
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 207 CouchDB::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