App-Pod

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


Saves the last class name and its methods/options.

## retrieve\_cache

Returns the last stored class cache and its options.

## trim

Trim a line to fit the terminal width.
Handles also escape codes within the line.

# ENVIRONMENT

Install bash completion support.

    % apt install bash-completion

Install tab completion.

    % source bash_completion_pod

lib/App/Pod.pm  view on Meta::CPAN

    $disk_cache;
}

#
# Output
#

=head2 trim

Trim a line to fit the terminal width.
Handles also escape codes within the line.

=cut

sub trim {
    my ( $line ) = @_;
    state $esc            = qr{ \033\[ [\d;]+ m    }x;
    state $data           = qr{ (?: (?!$esc) . )++ }x;
    state $data_or_escape = qr{ (?<data>$data) | (?<esc>$esc) }x;
    state $term_width     = Pod::Query::get_term_width();
    state $replacement    = " ...";
    state $width_raw      = $term_width - length( $replacement );
    state $base_width = $width_raw >= 0 ? $width_raw : 0;  # To avoid negatives.

    # Figure out the total len of the line (uncolored).
    my $total_chars = 0;
    my @detailed_line_parts;
    while ( $line =~ /$data_or_escape/g ) {
        my $part = {%+};
        $total_chars += $part->{len} = length( $part->{data} // "" );
        push @detailed_line_parts, $part;
    }

    # No need to trim.
    return $line if $total_chars <= $term_width;

    # Need to trim.
    my @parts;
    my $size_exceeded;
    my $so_far_len = 0;
    for my $part ( @detailed_line_parts ) {

        # Handle escape codes.
        if ( not $part->{len} ) {
            push @parts, $part->{esc};    # Add escapes back.
            last if $size_exceeded;       # Done.
            next;
        }

        # Handle trailing escapes.
        last if $size_exceeded;

        # Trim line if it would be too long.
        if ( $so_far_len + $part->{len} > $base_width ) {
            $size_exceeded = 1;  # Still need to possibly add a trailing escape.

            # Limit line to allowed width.
            $part->{data} = substr(
                $part->{data},
                0,
                $base_width - $so_far_len,    # How much space is left.
            ) . $replacement;
        }

        $so_far_len += $part->{len};

t/01-usage-simple.t  view on Meta::CPAN

              prepare
              proxy
              put
              put_p
              request_timeout
              server
              socket_options
              start
              start
              start_p
              term_escape
              transactor
              weaken
              websocket
              websocket_p
            }
        ],
    },
    {
        name            => "class_options - Mojo2::UserAgent2",
        input           => [qw( Mojo2::UserAgent2 --class_options )],

t/01-usage-simple.t  view on Meta::CPAN

            "key",                "max_connections",
            "max_redirects",      "max_response_size",
            "monkey_patch",       "options",
            "options_p",          "patch",
            "patch_p",            "post",
            "post_p",             "prepare",
            "proxy",              "put",
            "put_p",              "request_timeout",
            "server",             "socket_options",
            "start",              "start",
            "start_p",            "term_escape",
            "transactor",         "weaken",
            "websocket",          "websocket_p"
        ],
    },
    {
        name  => "class_options, tool_options - Mojo2::UserAgent2",
        input => [qw( Mojo2::UserAgent2 --class_options --tool_options )],
        expected_output => [
            "--all",      "--class_options",
            "--co",       "--dd",

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

package Mojo2::UserAgent;
use Mojo::Base 'Mojo::EventEmitter';

# "Fry: Since when is the Internet about robbing people of their privacy?
#  Bender: August 6, 1991."
use Mojo::IOLoop;
use Mojo::Promise;
use Mojo::Util qw(monkey_patch term_escape);
use Mojo::UserAgent::CookieJar;
use Mojo::UserAgent::Proxy;
use Mojo::UserAgent::Server;
use Mojo::UserAgent::Transactor;
use Scalar::Util qw(weaken);

use constant DEBUG => $ENV{MOJO_CLIENT_DEBUG} || 0;

has ca                 => sub { $ENV{MOJO_CA_FILE} };
has cert               => sub { $ENV{MOJO_CERT_FILE} };

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

    weaken $self;
    $tx->on( resume => sub { $self->_write( $id ) } );
    $self->_write( $id );
}

sub _read {
    my ( $self, $id, $chunk ) = @_;

    # Corrupted connection
    return $self->_remove( $id ) unless my $tx = $self->{connections}{$id}{tx};
    warn term_escape "-- Client <<< Server (@{[_url($tx)]})\n$chunk\n" if DEBUG;
    $tx->client_read( $chunk );
    $self->_finish( $id ) if $tx->is_finished;
}

sub _redirect {
    my ( $self, $c, $old ) = @_;
    return undef unless my $new = $self->transactor->redirect( $old );
    return undef unless @{ $old->redirects } < $self->max_redirects;
    return $self->_start( $c->{ioloop}, $new, delete $c->{cb} );
}

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

sub _url { shift->req->url->to_abs }

sub _write {
    my ( $self, $id ) = @_;

    # Protect from resume event recursion
    my $c = $self->{connections}{$id};
    return if !( my $tx = $c->{tx} ) || $c->{writing};
    local $c->{writing} = 1;
    my $chunk = $tx->client_write;
    warn term_escape "-- Client >>> Server (@{[_url($tx)]})\n$chunk\n" if DEBUG;
    return unless length $chunk;

    weaken $self;
    $c->{ioloop}->stream( $id )
      ->write( $chunk => sub { $self && $self->_write( $id ) } );
}

1;

=encoding utf8

t/cpan/ojo.pm  view on Meta::CPAN

variations.

  $ perl -Mojo -E 'a("/hello" => {text => "Hello Mojo!"})->start' daemon

=head2 b

  my $stream = b('lalala');

Turn string into a L<Mojo::ByteStream> object.

  $ perl -Mojo -E 'b(g("mojolicious.org")->body)->html_unescape->say'

=head2 c

  my $collection = c(1, 2, 3);

Turn list into a L<Mojo::Collection> object.

=head2 d

  my $res = d('example.com');



( run in 0.755 second using v1.01-cache-2.11-cpan-c21f80fb71c )