Skip to content

Instantly share code, notes, and snippets.

@hesco
Created January 19, 2013 10:24
Show Gist options
  • Save hesco/4571823 to your computer and use it in GitHub Desktop.
Save hesco/4571823 to your computer and use it in GitHub Desktop.
Curious to know what may be illegal about this syntax . . .
perl t/103-sometest.t
ok 1 - use MyApp::SomeModule;
param(): illegal syntax at lib/MyApp/Base.pm line 58
# Tests were run but no plan was declared and done_testing() was not seen.
------------------------------
package MyApp::Base;
use Moose;
use Carp;
use Exporter;
use Data::Dumper;
use File::Path qw( mkpath );
use Config::Simple::Extended;
use Log::Log4perl qw(get_logger :levels);
use Log::Log4perl::Config::PropertyConfigurator;
use lib qw( lib );
use MyApp::DB;
has 'debug' => (
is => 'rw',
isa => 'Int',
);
has 'cfg' => (
is => 'rw',
isa => 'Config::Simple',
builder => '_build_cfg',
);
has 'config_files' => (
is => 'ro',
isa => 'ArrayRef[Str]',
);
# required => 1,
has 'configuration' => (
is => 'rw',
isa => 'Config::Simple',
);
sub _build_cfg {
my $self = shift;
if(defined($self->configuration)){
return $self->configuration;
} elsif(defined($self->config_files)){
print STDERR "We have a config_files key which includes: " .
Dumper( $self->config_files )
if( $self->debug );
my $cfg;
undef($cfg);
foreach my $file (@{$self->config_files}){
print "Now applying $file to configuration hash \n"
if( $self->debug );
$cfg = Config::Simple::Extended->inherit({ # <---- Error points to this line
debug => $self->debug,
base_config => $cfg,
filename => $file });
}
print Dumper( $cfg->get_block("paths") )
if( $self->debug );
return $cfg;
} else {
my @caller = caller();
die "Constructor invoked with no Confirguration File."
. Dumper( \@caller );
}
}
1;
package MyApp::SomeModule;
use Moose;
use lib qw( lib );
extends 'MyApp::Base';
1;
------------------------------
t/103-sometest.t
#!/usr/bin/env perl
use strict;
use warnings;
use Test::Most;
use Test::WWW::Mechanize;
use lib qw( lib );
use_ok( 'MyApp::SomeModule' );
my $ini_base = '/etc/myapp/myapp_base.ini';
my $ini_additional = '/etc/myapp/myapp_additional.ini';
my $ymd = MyApp::SomeModule->new({
debug => 0,
config_files => [ $ini_base, $ini_additional ] });
isa_ok( $ymd, 'MyApp::SomeModule' );
done_testing();
exit;
@hesco
Copy link
Author

hesco commented Jan 19, 2013

(05:32:19 AM) hesco: Curious to know what may be illegal about this syntax . . . : https://gist.github.com/4571823
(05:40:11 AM) hesco: It seems that error is thrown by Config::Simple and relates to the syntax of my configuration file and not to the syntax of my code. Guess that is a never-mind.
(05:45:33 AM) hesco: found it. Config::Simple does not recognize a comma separated list assigned to a key. Quoting the list made it work. Will have to sort out how to turn that back into a list later when I need that list.
(05:48:44 AM) hesco: Except that the perldoc says it does support comma separated lists, though perhaps not in .ini files as their example uses one of the other supported formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment