Skip to content
Browse files

move HashStore helper into HashStore class

  • Loading branch information...
1 parent 9c169aa commit 76ef495fce47d96bffc3eab7a39676706914964e @jberger committed
Showing with 25 additions and 21 deletions.
  1. +1 −21 lib/Moodule/Build/Base.pm
  2. +24 −0 lib/Moodule/Build/HashStore.pm
View
22 lib/Moodule/Build/Base.pm
@@ -3,27 +3,7 @@ package Moodule::Build::Base;
use Moo;
use Carp;
-use Moodule::Build::HashStore;
-
-sub HashStore {
- my $name = shift or croak "Must specify the name of the HashStore";
- my $default = @_ ? shift : {};
- if ($default && ref $default ne 'HASH') {
- croak "HashStore default must be a hash reference";
- }
-
- return (
- "_$name",
- is => 'rw',
- init_arg => $name,
- handles => { $name => 'accessor' },
- coerce => sub {
- return $_[0] if eval{ $_[0]->isa('Moodule::Build::HashStore') };
- return Moodule::Build::HashStore->new( data => $_[0] );
- },
- default => sub { Moodule::Build::HashStore->new( data => $default ) },
- );
-}
+use Moodule::Build::HashStore qw/HashStore/;
has 'dist_name' => (
is => 'ro',
View
24 lib/Moodule/Build/HashStore.pm
@@ -1,6 +1,10 @@
package Moodule::Build::HashStore;
use Moo;
+use Carp;
+use Exporter 'import';
+
+our @EXPORT_OK = qw/HashStore/;
has 'data' => (
is => 'ro',
@@ -21,5 +25,25 @@ sub accessor {
return $data->{$key};
}
+sub HashStore {
+ my $name = shift or croak "Must specify the name of the HashStore";
+ my $default = @_ ? shift : {};
+ if ($default && ref $default ne 'HASH') {
+ croak "HashStore default must be a hash reference";
+ }
+
+ return (
+ "_$name",
+ is => 'rw',
+ init_arg => $name,
+ handles => { $name => 'accessor' },
+ coerce => sub {
+ return $_[0] if eval{ $_[0]->isa('Moodule::Build::HashStore') };
+ return Moodule::Build::HashStore->new( data => $_[0] );
+ },
+ default => sub { Moodule::Build::HashStore->new( data => $default ) },
+ );
+}
+
1;

0 comments on commit 76ef495

Please sign in to comment.
Something went wrong with that request. Please try again.