Birendra Singh
Birendra Singh

Reputation: 103

Can't load application from file /perl/school-reports/script/reports No such file or directory at /usr/local/share/perl/5.34.0/Mojo/Server.pm line 59

I am stuck while running the project which has been created on Perl with Mojolicious module. here is the code of the file from where I am running the project using morbo command

   #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    use FindBin;
    BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
    use Mojolicious::Commands;
    $ENV{MOJO_USERAGENT_DEBUG} = 1;
    # Start command line interface for application
    Mojolicious::Commands->start_app('Reports');
    

Here is my Reports.pm file --

package Reports;
use Mojo::Base 'Mojolicious';
use MongoDB;
use BSON::Types ':all';
use Data::Dumper;

# This method will run once at server start
sub startup {
  my $self = shift;

  my $config = $self->plugin('Config');
  $self->attr(
    db => sub {
      MongoDB->connect('mongodb://localhost:27017/reports');
    }
  );
  $self->helper(
    'db' => sub {
      shift->app->db;
    }
  );
  $self->helper(
    'url' => sub {
      shift->req->url->base->to_string;
    }
  );

  $self->helper(
    user => sub {
      my $self = shift;
      if ($config->{test}) {
        my $user = $self->db->ns('reports.users')->find_id(bson_oid('5e3f1cdcb762464a2d7cde49'));
        return $user;
      }
      if ($self->session->{'sid'}) {
        my $user = $self->db->ns('reports.users')->find_id(bson_oid($self->session->{'user_oid'}));
        if (defined $user) {
          return $user;
        } else {
          return 0;
        }
      } else {
        return 0;
      }
    }
  );

  $self->helper(
    active_session => sub {
      my $self = shift;
      return 1 if $config->{test};
      if ($self->session->{'sid'}) {
        my $session = $self->db->ns('reports.sessions')->find_id($self->session->{'sid'});
        return 1 if defined $session;
      } else {
        return 0;
      }
    }
  );

  # $self->plugin('Status');

  $self->secrets($config->{secrets});

  # Router
  my $r = $self->routes;

  my $auth_route = $r->under('/')->to('login#check_auth');
  my $check_subscription_status = $auth_route->under->to('profile#check_subscription_status');

  my $admin = $auth_route->under(
    '/admin' => sub {
      my $c = shift;

      # Authenticated
      return 1 if $c->user->{admin};

      return 0;

    }
  );

  # my $under = $admin->under('/status')->name('status');
  # $self->plugin('Status' => { route => $under });

  $check_subscription_status->get('/classes')->to('classes#list', section_classes_menu => 1, section_classes => 1)->name('classes');
  $check_subscription_status->get('/classes/archived')->to('classes#archived', section_archived_classes => 1, section_classes_menu => 1)
    ->name('archived_classes');
  $check_subscription_status->get('/classes/new')->to('classes#new_class', id => 0, section_new_class => 1, section_classes_menu => 1)
    ->name('new_class');
  $check_subscription_status->get('/classes/edit/:id')->to('classes#edit', id => 0, section_classes => 1, section_classes_menu => 1)
    ->name('edit_class');
  $auth_route->get('/classes/:class_id/student/:student_id')->to('classes#get_student')->name('get_student');
  $auth_route->post('/classes/save/:id')->to('classes#save', id => 0)->name('save_class');
  $auth_route->get('/classes/archive/:id')->to('classes#save', archive => 1)->name('archive_class');
  $auth_route->get('/classes/restore/:id')->to('classes#save', restore => 1)->name('restore_class');
  $auth_route->post('/classes/csv_import/:id')->to('classes#csv_import')->name('csv_import');

  $auth_route->post('/classes/:id/add_student')->to('classes#add_student')->name('add_student');
  $auth_route->post('/classes/:class_id/save_student/')->to('classes#save_student')->name('save_student');
  $auth_route->post('/classes/:class_id/student/report/:student_id')->to('classes#create_report_for_student')->name('create_report_for_student');

  $auth_route->post('/classes/:class_id/student/report/update/:student_id')->to('classes#update_report_for_student')
    ->name('update_report_for_student');
  $auth_route->post('/classes/:class_id/student/update_rating')->to('classes#update_rating')->name('update_rating');

  $auth_route->post('/classes/:class_id/student/expand')->to('classes#expand_student')->name('expand_student');

  $auth_route->post('/classes/:class_id/student/collapse')->to('classes#expand_student', collapse => 1)->name('collapse_student');

  #$auth_route->get('/classes/:class_id/report/')->to('report#create_report')->name('create_report'); ???

  $auth_route->post('/classes/report/process_ai')->to('classes#process_ai')->name('report_process_ai');

  $auth_route->post('/classes/:class_id/report/:report_id/save_draft')->to('report#save_draft')->name('save_report_draft');

  $admin->get('/subjects/')->to('editor#topics', section_subjects => 1)->name('topics');
  $admin->get('/subjects/new')->to('editor#new_topic', section_subjects => 1)->name('new_topic');
  $admin->get('/subjects/edit/:id')->to('editor#edit_topic', section_subjects => 1)->name('edit_topic');
  $admin->post('/subjects/save/:id')->to('editor#save_topic', id => 0)->name('save_topic');
  $admin->get('/subjects/delete/:id')->to('editor#delete_topic')->name('delete_topic');
  $admin->post('/subjects/import_xls/:id')->to('editor#import_xls')->name('import_xls');

  $admin->get('/subjects/personal_project')->to('editor#personal_project', section_personal_project => 1)->name('personal_project');
  $admin->post('/subjects/personal_project/import_xls')->to('editor#import_xls_personal_project')->name('import_xls_personal_project');


  $admin->get('/templates')->to('templates#list', section_templates => 1)->name('templates');
  $admin->post('/templates/save/:template_id')->to('templates#save')->name('save_template');

  $admin->get('/texts')->to('texts#list', section_texts => 1)->name('texts');
  $admin->post('/texts/save/:text_id')->to('texts#save')->name('save_text');
  $admin->get('/texts/new')->to('texts#new_text')->name('new_text');
  $r->get('/texts/:url')->to('texts#get')->name('get_text');

  $check_subscription_status->get('/profile')->to('profile#index', section_profile => 1)->name('profile');
  $auth_route->post('/profile/update')->to('profile#update')->name('update_profile');
  $auth_route->post('/profile/update_password')->to('profile#update_password')->name('update_password');

  $r->get('/profile/pay/')->to('profile#pay')->name('pay');
  $auth_route->post('/profile/purchase')->to('profile#purchase')->name('purchase');

  $auth_route->post('/profile/subscribe')->to('profile#subscribe')->name('subscribe');
  $auth_route->post('/profile/subscribe/cancel')->to('profile#cancel_subscription')->name('cancel_subscription');
  $r->any('/profile/subscribe/confirm_hook')->to('profile#subscribe_confirm_hook')->name('subscribe_confirm_hook');
  $r->any('/profile/subscribe/cancel_hook')->to('profile#subscribe_cancel_hook')->name('subscribe_cancel_hook');

 # $r->any('/profile/subscribe/confirm_hook_test')->to('profile#subscribe_confirm_hook_test');
  $r->get('/profile/subscribe/confirm')->to('profile#subscribe_confirm_page');
  #$r->get('/profile/subscribe/cancel')->to('profile#subscribe_сancel_page');

  $admin->get('/users')->to('admin#users', section_users => 1)->name('users');
  $admin->get('/')->to('admin#root', section_admin => 1)->name('admin');
  $admin->get('/backups')->to('admin#backups', section_backups => 1)->name('backups');
  $admin->get('/backups/restore/#filename')->to('admin#restore_backup', section_backups => 1)->name('restore_backup');

  $admin->get('/dump')->to('admin#dump')->name('dump');

  $r->get('/')->to('index#index')->name('index');
  $r->get('/register')->to('register#form')->name('register_form');
  $r->post('/register')->to('register#register')->name('register');
  $r->get('/login')->to('login#form')->name('login_form');
  $r->get('/register')->to('register#index')->name('register_form');
  $r->post('/login')->to('login#login')->name('login');
  $r->get('/logout')->to('login#logout')->name('logout');
  $r->post('/login')->to('login#login')->name('login');
  $r->post('/end_session')->to('login#end_session')->name('end_session');

  $r->get('/restore_password')->to('login#restore_password_form')->name('restore_password_form');
  $r->post('/restore_password')->to('login#restore_password')->name('restore_password');

  $r->get('/change_password/:hash')->to('login#change_password_form')->name('change_password_form');
  $r->post('/change_password/:hash')->to('login#change_password')->name('change_password');

  $admin->get('/delete_user/:id')->to('admin#delete_user')->name('delete_user');
  $admin->get('/add_user_credits/:id')->to('admin#add_user_credits')->name('add_user_credits');
  $admin->get('/annulate_user_subscription/:id')->to('admin#annulate_user_subscription')->name('annulate_user_subscription');
  $admin->get('/expire_user_trial/:id')->to('admin#expire_user_trial')->name('expire_user_trial');
  $admin->get('/end_annual_user_subscription/:id')->to('admin#end_annual_user_subscription')->name('end_annual_user_subscription');
  $admin->get('/send_test_email/:id')->to('admin#send_test_email')->name('send_test_email');
  $admin->get('/create_product')->to('admin#create_product')->name('create_product');
  $admin->get('/create_plan')->to('admin#create_plan')->name('create_plan');
  $r->get('/country')->to('register#countries')->name('countries');
  $r->get('/country/check')->to('register#check_country')->name('check_country');
  $r->get('/login/check')->to('register#check_login')->name('check_login');

  $r->get('/contact')->to('contact#form')->name('contact');
  $r->post('/contact/send')->to('contact#send_contact_message')->name('send_contact_message');

  # git
  $admin->get(
    '/git' => sub {
      my $self = shift;
      `cd /home/school-reports;git pull origin master;ubic restart reports;`;
    }
  )->name('git');
};

All modules has been installed successfully and trying to run the project using morbo command. I am getting the error while running the project. Not sure why even each module and files are there. also Server.pm file is there in the specified path.

Please help me to run this project. The project is in Perl and ep templates for CPAN. Please confirm what I am missing to run the project.

Upvotes: 1

Views: 69

Answers (0)

Related Questions