/[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 264 by dpavlin, Wed Aug 19 12:45:07 2009 UTC revision 396 by dpavlin, Tue Sep 8 17:30:14 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  our $ip      = '172.16.10.1';  tie our $ip,      'server::tie', 'server_ip' => '172.16.10.1';
9  our $netmask = '255.255.255.0';  tie our $netmask, 'server::tie', 'natmask'   => '255.255.255.0';
10  our $bcast   = '172.16.10.255';  tie our $bcast,   'server::tie', 'bcast'     => '172.16.10.254';
11    tie our $ip_from, 'server::tie', 'ip_from'   => 10;
12  if ( my $dev = $ENV{DEV} ) {  tie our $ip_to,   'server::tie', 'ip_to'     => 100;
13          my $ifconfig = `ifconfig $dev`;  tie our $domain,  'server::tie', 'domain'    => 'pxelator.lan';
14          ( $ip, $bcast, $netmask ) = ( $1, $2, $3 ) if $ifconfig =~ m{inet addr:(\S+)\s+Bcast:(\S+)\s+Mask:(\S+)}s;  tie our $new_clients, 'server::tie', 'new_clients' => $ip_to - $ip_from;
         warn "DEV $dev $ip $bcast $netmask";  
 }  
   
 our ( $ip_from, $ip_to ) = ( 10, 100 );  
   
 our $domain_name = 'pxelator.lan';  
15    
16  our $base_dir = '/srv/pxelator';  warn "DEV $ip $bcast $netmask";
17    
18  our $conf = "$base_dir/conf/$ip";  our $conf = "$base_dir/conf";
19  mkdir $conf unless -e $conf;  mkdir $conf unless -e $conf;
20    
21    sub conf {
22            warn "## conf $conf";
23            $conf;
24    }
25    
26  use Module::Refresh qw//;  use Module::Refresh qw//;
27  sub refresh {  sub refresh {
28          Module::Refresh->refresh;          Module::Refresh->refresh;
# Line 50  sub shared { Line 50  sub shared {
50          return $value;          return $value;
51  }  }
52    
53    sub conf_default { shared($_[0]) || $_[1] }
54    
55  sub debug { shared('debug', @_) || 0 }  sub debug { shared('debug', @_) || 0 }
56    
57  warn "loaded";  warn "loaded";
58    
59  1;  
60    package server::tie;
61    
62    use File::Slurp;
63    use Data::Dump qw/dump/;
64    
65    use server;
66    
67    sub TIESCALAR {
68            warn dump @_;
69            my ($class,$name,$default) = @_;
70    
71            my $path = $server::base_dir . '/conf/' . $name;
72    
73            my $o = {
74                    path => $path,
75            };
76            write_file $o->{path}, $default unless -f $o->{path};
77    
78    warn "TIESCALAR $name ", $o->{path}, " [$default]";
79    
80            bless \$o,$class;
81    }
82    
83    sub STORE {
84            warn dump @_;
85            my ( $self, $value ) = @_;
86            write_file $$self->{path}, $value;
87    }
88    
89    sub FETCH {
90            warn dump @_;
91            my $self = shift;
92            read_file $$self->{path};
93    }
94    
95    3;

Legend:
Removed from v.264  
changed lines
  Added in v.396

  ViewVC Help
Powered by ViewVC 1.1.26