Mojolicious

 view release on metacpan or  search on metacpan

lib/Mojo/File.pm  view on Meta::CPAN

  chmod $mode, $$self or croak qq{Can't chmod file "$$self": $!};
  return $self;
}

sub copy_to {
  my ($self, $to) = @_;
  copy($$self, $to) or croak qq{Can't copy file "$$self" to "$to": $!};
  return $self->new(-d $to ? ($to, File::Basename::basename $self) : $to);
}

sub curfile { __PACKAGE__->new(Cwd::realpath((caller)[1])) }

sub dirname { $_[0]->new(scalar File::Basename::dirname ${$_[0]}) }

sub download {
  my ($self, $url, $options) = (shift, shift, shift // {});
  my $ua = $options->{ua}
    || do { require Mojo::UserAgent; Mojo::UserAgent->new(max_redirects => 10, max_response_size => 0) };
  my $tx = _download_error($ua->transactor->download($ua->head($url => $options->{headers} // {}), $$self));
  return $tx ? !!_download_error($ua->start($tx)) : 1;
}

lib/Mojo/Util.pm  view on Meta::CPAN

  croak 'CryptX 0.080+ required for encrypted cookie support' unless CRYPTX;

  my $dk = $ENCRYPTION{$key}{$salt} ||= Crypt::KeyDerivation::pbkdf2($key, $salt);
  my $iv = Crypt::PRNG::random_bytes(12);
  my ($ct, $tag) = Crypt::AuthEnc::ChaCha20Poly1305::chacha20poly1305_encrypt_authenticate($dk, $iv, '', $value);

  return join '-', Crypt::Misc::encode_b64($ct), Crypt::Misc::encode_b64($iv), Crypt::Misc::encode_b64($tag);
}

sub extract_usage {
  my $file = @_ ? "$_[0]" : (caller)[1];

  open my $handle, '>', \my $output;
  pod2usage -exitval => 'noexit', -input => $file, -output => $handle;
  $output =~ s/^.*\n|\n$//;
  $output =~ s/\n$//;

  return unindent($output);
}

sub generate_secret {

lib/Mojolicious/Command.pm  view on Meta::CPAN


sub create_dir {
  my ($self, $path) = @_;
  return $self->_loud("  [exist] $path") if -d $path;
  path($path)->make_path;
  return $self->_loud("  [mkdir] $path");
}

sub create_rel_dir { $_[0]->create_dir($_[0]->rel_file($_[1])) }

sub extract_usage { Mojo::Util::extract_usage((caller)[1]) }

sub help { print shift->usage }

sub rel_file { path->child(split(/\//, pop)) }

sub render_data {
  my ($self, $name) = (shift, shift);
  my $template = Mojo::Template->new($self->template)->name("template $name from DATA section");
  my $output   = $template->render(data_section(ref $self, $name), @_);
  return ref $output ? die $output : $output;

lib/Mojolicious/Lite.pm  view on Meta::CPAN

use Mojo::Base 'Mojolicious';

# "Bender: Bite my shiny metal ass!"
use Mojo::File qw(path);
use Mojo::UserAgent::Server;
use Mojo::Util qw(monkey_patch);

sub import {

  # Remember executable for later
  $ENV{MOJO_EXE} ||= (caller)[1];

  # Reuse home directory if possible
  local $ENV{MOJO_HOME} = path($ENV{MOJO_EXE})->dirname->to_string unless $ENV{MOJO_HOME};

  # Initialize application class
  my $caller = caller;
  no strict 'refs';
  push @{"${caller}::ISA"}, 'Mojolicious';

  # Generate moniker based on filename



( run in 1.573 second using v1.01-cache-2.11-cpan-a3c8064c92c )