From: Robert 'phaylon' Sedlacek Date: Wed, 11 Jul 2012 21:39:16 +0000 (+0000) Subject: simulated hostname file and ability to declare a different file for Host probe X-Git-Tag: v0.001_001~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b06b139dc7e5a4f4e0e33074c9bdc32a913c5895;p=scpubgit%2FSystem-Introspector.git simulated hostname file and ability to declare a different file for Host probe --- diff --git a/lib/System/Introspector/Probe/Host.pm b/lib/System/Introspector/Probe/Host.pm index 4330c2d..530875f 100644 --- a/lib/System/Introspector/Probe/Host.pm +++ b/lib/System/Introspector/Probe/Host.pm @@ -8,6 +8,8 @@ use System::Introspector::Util qw( transform_exceptions ); +has hostname_file => (is => 'ro', default => sub {'/etc/hostname' }); + sub gather { my ($self) = @_; return transform_exceptions { @@ -43,7 +45,7 @@ sub _gather_uname_info { sub _gather_hostname { my ($self) = @_; - my $hostname = output_from_file '/etc/hostname'; + my $hostname = output_from_file $self->hostname_file; chomp $hostname; $hostname =~ s{(?:^\s+|\s+$)}{}g; return $hostname; diff --git a/t/data/hostname b/t/data/hostname new file mode 100644 index 0000000..3929a1c --- /dev/null +++ b/t/data/hostname @@ -0,0 +1 @@ +foo-bar diff --git a/t/host.t b/t/host.t index 4e64d9e..04ef558 100644 --- a/t/host.t +++ b/t/host.t @@ -1,10 +1,13 @@ use strictures 1; use Test::More; +use FindBin; use System::Introspector::Probe::Host; -my $probe = System::Introspector::Probe::Host->new; -my $data = $probe->gather; +my $probe = System::Introspector::Probe::Host->new( + hostname_file => "$FindBin::Bin/data/hostname", +); +my $data = $probe->gather; ok length($data->{hostname}), 'found a hostname'; ok defined($data->{uname}{ $_ }), "has uname $_" for qw(