diff options
author | Tom Feist <shabble@metavore.org> | 2010-10-10 22:11:52 +0000 |
---|---|---|
committer | Tom Feist <shabble@metavore.org> | 2010-10-10 22:11:52 +0000 |
commit | 745b2901e2f635d6a57cbe3e40695a6fe751f97b (patch) | |
tree | 9f860e07ceb4182d1a6e19553275060fd401ca67 /feature-tests/subscript.pl | |
parent | added a brief proof-of-concept for loading/reloading additional functions on the (diff) | |
download | irssi-scripts-745b2901e2f635d6a57cbe3e40695a6fe751f97b.tar.gz irssi-scripts-745b2901e2f635d6a57cbe3e40695a6fe751f97b.zip |
tidied up loading code, added demo of calling func in outer scope
Diffstat (limited to '')
-rw-r--r-- | feature-tests/subscript.pl | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/feature-tests/subscript.pl b/feature-tests/subscript.pl index 74a5afe..8550409 100644 --- a/feature-tests/subscript.pl +++ b/feature-tests/subscript.pl @@ -19,6 +19,10 @@ my $functions = {}; init(); +sub _input { + return int rand 1000; +} + sub load { my $file = shift; my $funcs; @@ -26,16 +30,32 @@ sub load { print "Loading from file: $file"; $funcs = do $file; } + if (not defined $funcs) { + if ($@) { + print "failed to parse $file: $@"; - return unless ref $funcs eq 'HASH'; - print "Got hashref from file"; + } elsif ($!) { + print "failed to read $file: $!"; + + } + return; + } + my $ref = ref $funcs; + if ($ref ne 'HASH') { + print "$file didn't return a hashref: ", defined $ref ? $ref : 'undef'; + return; + } foreach my $name (keys %$funcs) { my $func = $funcs->{$name}; + if (exists $functions->{$name}) { + print "Redefining function $name"; + } else { + print "adding function: $name"; + } $functions->{$name} = $func; } - $functions = $funcs; print "Loaded " . scalar(keys(%$funcs)) . " functions"; } |