<commit_before>=head1 NAME

SGN::Role::Site::TestMode - adds the concept of 'test mode' to a site

=cut

package SGN::Role::Site::TestMode;

use Moose::Role;
use namespace::autoclean;

use Carp;
use File::Spec;

use Data::Visitor::Callback;

requires 'config', 'path_to', 'finalize_config';

after 'finalize_config' => \&_reroot_test_mode_files;

=head1 DESCRIPTION

This role requires that Catalyst::Plugin::ConfigLoader (or other
plugin providing finalize_config) be activated.

It does two things: adds a C<test_mode> attribute, and reroots
paths to files and directories in the global configuration if the app
is in test mode.

=head1 METHODS

=head2 test_mode

read-only sub, boolean telling whether the site is now running in
test mode.

By default, this attribute is true if the MYAPP_TEST_MODE environment
variable is set to a true value.

=cut

sub test_mode {
    my $c = shift;
    my $app_name = ref($c) || $c;
    return $ENV{ uc($app_name).'_TEST_MODE' };
}

=head1 CONFIGURATION PATH REROOTING

At load time, if the app is running in test mode, this role will
reroot paths in the global configuration to point into a tree of test<commit_msg>fix ->test_mode, did not actually work from *within* the app due to catalyst's weird handling of env variables.  :-(<commit_after>=head1 NAME

SGN::Role::Site::TestMode - adds the concept of 'test mode' to a site

=cut

package SGN::Role::Site::TestMode;

use Moose::Role;
use namespace::autoclean;

use Carp;
use File::Spec;

use Data::Visitor::Callback;

requires 'config', 'path_to', 'finalize_config';

after 'finalize_config' => \&_reroot_test_mode_files;

=head1 DESCRIPTION

This role requires that Catalyst::Plugin::ConfigLoader (or other
plugin providing finalize_config) be activated.

It does two things: adds a C<test_mode> attribute, and reroots
paths to files and directories in the global configuration if the app
is in test mode.

=head1 METHODS

=head2 test_mode

read-only sub, boolean telling whether the site is now running in
test mode.

By default, this attribute is true if the MYAPP_TEST_MODE environment
variable is set to a true value.

=cut

sub test_mode {
    my $c = shift;
    my $app_name = ref($c) || $c;
    my $env_name = uc($app_name).'_TEST_MODE';
    return _env($c)->{$env_name} ? 1 : 0;
}
sub _env {
    my ( $c ) = @_;
    return ref($c) ? $c->engine->env : \%ENV;
}


=head1 CONFIGURATION PATH REROOTING

At load time, if the app is running in test mode, this role will
reroot paths in the global configuration to point into a tree of test
{'fraction_non_alphanumeric': 0.09499408750492708, 'fraction_numerical': 0.004729996058336618, 'mean_word_length': 4.590308370044053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2242038', 'n_tokens_mistral': 838, 'n_tokens_neox': 806, 'n_words': 329}