| 1 |
package Dahdi::Utils; |
| 2 |
|
| 3 |
# Accessors (miniperl does not have Class:Accessor) |
| 4 |
our $AUTOLOAD; |
| 5 |
sub AUTOLOAD { |
| 6 |
my $self = shift; |
| 7 |
my $name = $AUTOLOAD; |
| 8 |
$name =~ s/.*://; # strip fully-qualified portion |
| 9 |
return if $name =~ /^[A-Z_]+$/; # ignore special methods (DESTROY) |
| 10 |
my $key = uc($name); |
| 11 |
my $val = shift; |
| 12 |
if (defined $val) { |
| 13 |
#print STDERR "set: $key = $val\n"; |
| 14 |
return $self->{$key} = $val; |
| 15 |
} else { |
| 16 |
if(!exists $self->{$key}) { |
| 17 |
#$self->xpp_dump; |
| 18 |
#die "Trying to get uninitialized '$key'"; |
| 19 |
} |
| 20 |
my $val = $self->{$key}; |
| 21 |
#print STDERR "get: $key ($val)\n"; |
| 22 |
return $val; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
# Initialize ProcFS and SysFS pathes, in case the user set |
| 27 |
# DAHDI_VIRT_TOP |
| 28 |
BEGIN { |
| 29 |
if (exists $ENV{DAHDI_VIRT_TOP}) { |
| 30 |
$Dahdi::virt_base = $ENV{DAHDI_VIRT_TOP}; |
| 31 |
} else { |
| 32 |
$Dahdi::virt_base = ''; |
| 33 |
} |
| 34 |
$Dahdi::proc_dahdi_base = "$Dahdi::virt_base/proc/dahdi"; |
| 35 |
$Dahdi::proc_usb_base = "$Dahdi::virt_base/proc/bus/usb"; |
| 36 |
$Dahdi::sys_base = "$Dahdi::virt_base/sys"; |
| 37 |
} |
| 38 |
|
| 39 |
sub xpp_dump($) { |
| 40 |
my $self = shift || die; |
| 41 |
printf STDERR "Dump a %s\n", ref($self); |
| 42 |
foreach my $k (sort keys %{$self}) { |
| 43 |
my $val = $self->{$k}; |
| 44 |
$val = '**UNDEF**' if !defined $val; |
| 45 |
printf STDERR " %-20s %s\n", $k, $val; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
# Based on Autoloader |
| 50 |
|
| 51 |
sub import { |
| 52 |
my $pkg = shift; |
| 53 |
my $callpkg = caller; |
| 54 |
|
| 55 |
#print STDERR "import: $pkg, $callpkg\n"; |
| 56 |
# |
| 57 |
# Export symbols, but not by accident of inheritance. |
| 58 |
# |
| 59 |
die "Sombody inherited Dahdi::Utils" if $pkg ne 'Dahdi::Utils'; |
| 60 |
no strict 'refs'; |
| 61 |
*{ $callpkg . '::AUTOLOAD' } = \&AUTOLOAD; |
| 62 |
*{ $callpkg . '::xpp_dump' } = \&xpp_dump; |
| 63 |
} |
| 64 |
|
| 65 |
1; |