Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

get_data_section($name) should not die if there is no __DATA__ section. #2

Merged
merged 1 commit into from

2 participants

@tokuhirom

Current version dies with folllowing message.

Can't use an undefined value as a HASH reference at /Users/tokuhirom/.plenv/versions/5.16.3/lib/perl5/site_perl/5.16.3/Data/Section/Simple.pm line 19

It's not user friendly.

@miyagawa miyagawa merged commit adc26fc into miyagawa:master
@tokuhirom tokuhirom deleted the tokuhirom:no-DATA-fix branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +3 −1 lib/Data/Section/Simple.pm
  2. +7 −0 t/no-datat.t
View
4 lib/Data/Section/Simple.pm
@@ -16,7 +16,9 @@ sub get_data_section {
my $self = ref $_[0] ? shift : __PACKAGE__->new(scalar caller);
if (@_) {
- return $self->get_data_section->{$_[0]};
+ my $all = $self->get_data_section;
+ return unless $all;
+ return $all->{$_[0]};
} else {
my $d = do { no strict 'refs'; \*{$self->{package}."::DATA"} };
return unless defined fileno $d;
View
7 t/no-datat.t
@@ -0,0 +1,7 @@
+use strict;
+use Data::Section::Simple qw(get_data_section);
+use Test::More;
+
+is get_data_section('foo.html'), undef, 'Do not die.';
+
+done_testing;
Something went wrong with that request. Please try again.