App-Dochazka-REST
view release on metacpan or search on metacpan
lib/App/Dochazka/REST/Mason.pm view on Meta::CPAN
=head1 NAME
App::Dochazka::REST::Mason - Mason interpreter singleton
=head1 SYNOPSIS
use App::Dochazka::REST::Mason qw( $interp );
=head1 DESCRIPTION
Mason interpreter singleton.
=cut
=head1 EXPORTS
=cut
use Exporter qw( import );
our @EXPORT_OK = qw( $comp_root $interp );
=head1 PACKAGE VARIABLES
This module stores and initializes the L<Mason> interpreter singleton object.
=cut
our ( $comp_root, $interp );
=head1 FUNCTIONS
=head2 init_singleton
Initialize the C<$interp> singleton. Takes a C<comp_root> and a
C<data_dir> which are expected to exist and be owned by the effective user.
Idempotent.
FIXME: Add parameters to the Mason->new() call as needed.
=cut
sub init_singleton {
my @ARGS = @_;
my %ARGS;
my $status = $CELL->status_ok;
try {
%ARGS = validate(
@ARGS, {
comp_root => { type => SCALAR },
data_dir => { type => SCALAR },
}
);
die "Mason comp_root $ARGS{comp_root} has a problem" unless
(
-r $ARGS{comp_root} and
-w $ARGS{comp_root} and
-x $ARGS{comp_root}
);
die "Mason comp_root $ARGS{data_dir} has a problem" unless
(
-r $ARGS{comp_root} and
-w $ARGS{comp_root} and
-x $ARGS{comp_root}
);
$interp = Mason->new(
comp_root => $ARGS{comp_root},
data_dir => $ARGS{data_dir},
class_header => q(
use App::CELL qw( $CELL $log $meta $site );
),
);
$comp_root = $ARGS{comp_root};
} catch {
$status = $CELL->status_crit( 'DOCHAZKA_MASON_INIT_FAIL', args => [ $_ ] );
};
return $status;
}
1;
( run in 0.506 second using v1.01-cache-2.11-cpan-df04353d9ac )