summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Rothenberg <rrwo@cpan.org>2020-03-25 12:34:06 +0000
committerRobert Rothenberg <rrwo@cpan.org>2020-03-25 12:34:06 +0000
commit3d5f60f0b01a433275778a8435605affd67f99e9 (patch)
tree74587da64d8ae35a333466b37f640b204466f44a
parentfccb94a126a551fdcd386d341e9be16297eafccc (diff)
Set up the load method in a BEGIN block instead of import
This fixes #5.
-rw-r--r--Changes2
-rw-r--r--lib/Sys/CpuLoad.pm3
-rw-r--r--t/02-legacy.t13
3 files changed, 16 insertions, 2 deletions
diff --git a/Changes b/Changes
index 581fbfc..9786d56 100644
--- a/Changes
+++ b/Changes
@@ -9,6 +9,8 @@ Revision history for Perl extension {{$dist->name}}:
[Bug Fixes]
- The return value of getloadavg is now checked, #4.
+ - The load method is set up in a BEGIN block instead of import, #5.
+
[Documentation]
- Update POD about changes in version 0.12.
diff --git a/lib/Sys/CpuLoad.pm b/lib/Sys/CpuLoad.pm
index ed9246d..33ec930 100644
--- a/lib/Sys/CpuLoad.pm
+++ b/lib/Sys/CpuLoad.pm
@@ -49,7 +49,7 @@ On error, it will return an array of C<undef> values.
=cut
-sub import {
+sub BEGIN {
my $this = __PACKAGE__;
my $os = lc $^O;
@@ -102,7 +102,6 @@ sub import {
};
}
- goto &Exporter::import;
}
=head1 SEE ALSO
diff --git a/t/02-legacy.t b/t/02-legacy.t
new file mode 100644
index 0000000..f1b65d2
--- /dev/null
+++ b/t/02-legacy.t
@@ -0,0 +1,13 @@
+use Test::Most;
+
+use Sys::CpuLoad ();
+
+my @load = Sys::CpuLoad::load();
+
+cmp_deeply
+ \@load,
+ [ (re(qr/^\d(\.\d+)?(e[\-\+]\d+)?$/)) x 3 ], 'load';
+
+diag "@load";
+
+done_testing;