/[pxelator]/lib/PXElator/server.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

Diff of /lib/PXElator/server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 134 by dpavlin, Tue Aug 4 13:18:36 2009 UTC revision 393 by dpavlin, Tue Sep 8 16:54:35 2009 UTC
# Line 3  package server; Line 3  package server;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6    our $base_dir = '/srv/pxelator';
7    
8    tie our $ip,      'server::tie', 'ip'      => '172.16.10.1';
9    tie our $netmask, 'server::tie', 'natmask' => '255.255.255.0';
10    tie our $bcast,   'server::tie', 'bcast'   => '172.16.10.254';
11    tie our $ip_from, 'server::tie', 'ip_from' => 10;
12    tie our $ip_to,   'server::tie', 'ip_to'   => 100;
13    tie our $domain,  'server::tie', 'domain'  => 'pxelator.lan';
14    
15    warn "DEV $ip $bcast $netmask";
16    
17    our $conf = "$base_dir/conf/$ip";
18    mkdir $conf unless -e $conf;
19    
20    sub conf {
21            warn "## conf $conf";
22            $conf;
23    }
24    
25  use Module::Refresh qw//;  use Module::Refresh qw//;
26  sub x_refresh { Module::Refresh->refresh };  sub refresh {
27            Module::Refresh->refresh;
28            my $from = (caller(1))[3];
29            $from =~ s{^(\w+)::.+$}{$1};
30            my $eval = '$' . $from . '::debug = server::debug();';
31            warn "refresh $eval\n";
32            eval $eval;
33            warn $@ if $@;
34    };
35    
36    mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' );
37    
38    use File::Slurp;
39    sub shared {
40            my ($name, $value) = @_;
41    
42            my $path ="$conf/$name";
43            if ( defined $value ) {
44                    write_file $path, $value;
45                    warn "update $path = $value";
46            } else {
47                    $value = read_file $path if -e $path;
48            }
49            return $value;
50    }
51    
52  our $ip      = '172.16.10.1';  sub conf_default { shared($_[0]) || $_[1] }
 our $netmask = '255.255.255.0';  
53    
54  our ( $ip_from, $ip_to ) = ( 10, 100 );  sub debug { shared('debug', @_) || 0 }
55    
56  our $base_dir = '/srv/pxelator';  warn "loaded";
57    
 use config;  
58    
59  our $debug;  package server::tie;
 sub debug { $debug = config::shared('debug', @_) || 0 }  
60    
61  warn "loaded";  use File::Slurp;
62    use Data::Dump qw/dump/;
63    
64    use server;
65    
66    sub TIESCALAR {
67            warn dump @_;
68            my ($class,$name,$default) = @_;
69    
70            my $path = $server::base_dir;
71            if ( $name eq 'ip' ) {
72                    $path .= '/conf/' . $ip;
73            } else {
74                    $path .= '/conf/' . $server::ip;
75            }
76    
77            my $o = {
78                    path => "$path/$name",
79            };
80            write_file $o->{path}, $default unless -f $o->{path};
81    
82    warn "TIESCALAR $name ", $o->{path}, " [$default]";
83    
84            bless \$o,$class;
85    }
86    
87    sub STORE {
88            warn dump @_;
89            my ( $self, $value ) = @_;
90            write_file $$self->{path}, $value;
91    }
92    
93    sub FETCH {
94            warn dump @_;
95            my $self = shift;
96            read_file $$self->{path};
97    }
98    
99  1;  3;

Legend:
Removed from v.134  
changed lines
  Added in v.393

  ViewVC Help
Powered by ViewVC 1.1.26