<commit_before>package MediaWords::Controller::Root;
use Modern::Perl "2012";
use MediaWords::CommonLibs;

use strict;
use warnings;
use base 'Catalyst::Controller';
use Data::Dumper;
use MediaWords::Util::Config;

#
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
#
__PACKAGE__->config->{ namespace } = '';

=head1 NAME

MediaWords::Controller::Root - Root Controller for MediaWords

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

=head2 default

=cut

sub default : Private
{
    my ( $self, $c ) = @_;

    # Hello World
    my $config = MediaWords::Util::Config::get_config;

    my $default_home_page = $config->{ mediawords }->{ default_home_page };

    $default_home_page //= 'media/list';
    $c->response->redirect( $c->uri_for( $default_home_page ) );
}

=head2 end

Attempt to render a view, if needed.

=cut 

sub end : ActionClass('RenderView')
{
    my ( $self, $c ) = @_;

    if ( scalar @{ $c->error } )
    {
        $c->stash->{ errors } = [ map { $_ } @{ $c->error } ];

        print STDERR "Handling error:\n";
        print STDERR Dumper( $c->stash->{ errors } );

        my $config = MediaWords::Util::Config::get_config;
        my $always_show_stack_traces = $config->{ mediawords }->{ always_show_stack_traces } eq 'yes';

        if ( $always_show_stack_traces )
        {
            $c->config->{ stacktrace }->{ enable } = 1;
        }

        if ( !( $c->debug() || $always_show_stack_traces ) )
        {
            $c->error( 0 );

            $c->stash->{ template } = 'public_ui/error_page.tt2';

            $c->response->status( 500 );
        }
    }

}

=head1 AUTHOR

<NAME>

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
<commit_msg>move begin to Root.pm to quiet catalyst errior<commit_after>package MediaWords::Controller::Root;
use Modern::Perl "2012";
use MediaWords::CommonLibs;

use strict;
use warnings;
use base 'Catalyst::Controller';
use Data::Dumper;
use MediaWords::Util::Config;

#
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
#
__PACKAGE__->config->{ namespace } = '';

=head1 NAME

MediaWords::Controller::Root - Root Controller for MediaWords

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

=head2 default

=cut

sub default : Private
{
    my ( $self, $c ) = @_;

    # Hello World
    my $config = MediaWords::Util::Config::get_config;

    my $default_home_page = $config->{ mediawords }->{ default_home_page };

    $default_home_page //= 'media/list';
    $c->response->redirect( $c->uri_for( $default_home_page ) );
}

sub begin : Private
{
    my ( $self, $c ) = @_;

    my $locale = $c->request->param( 'locale' );

    $c->response->headers->push_header( 'Vary' => 'Accept-Language' );    # hmm vary and param?
    $c->languages( $locale ? [ $locale ] : undef );

    #switch to english if locale param is not explicitly specified.
    $c->languages( $locale ? [ $locale ] : [ 'en' ] );
}


=head2 end

Attempt to render a view, if needed.

=cut 

sub end : ActionClass('RenderView')
{
    my ( $self, $c ) = @_;

    if ( scalar @{ $c->error } )
    {
        $c->stash->{ errors } = [ map { $_ } @{ $c->error } ];

        print STDERR "Handling error:\n";
        print STDERR Dumper( $c->stash->{ errors } );

        my $config = MediaWords::Util::Config::get_config;
        my $always_show_stack_traces = $config->{ mediawords }->{ always_show_stack_traces } eq 'yes';

        if ( $always_show_stack_traces )
        {
            $c->config->{ stacktrace }->{ enable } = 1;
        }

        if ( !( $c->debug() || $always_show_stack_traces ) )
        {
            $c->error( 0 );

            $c->stash->{ template } = 'public_ui/error_page.tt2';

            $c->response->status( 500 );
        }
    }

}

=head1 AUTHOR

<NAME>

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;

{'fraction_non_alphanumeric': 0.14717887154861944, 'fraction_numerical': 0.008643457382953182, 'mean_word_length': 2.911737089201878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '2470418', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1373, 'n_words': 372}