Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my $ua = Mojo::UserAgent->new();
- $ua->websocket('ws://localhost:4008/ebuge' => sub { # tried ws: and http:
- my ($ua, $tx) = @_;
- say "tx is $tx"; # Mojo::Transaction::HTTP=HASH(0xa029678)
- $DB::single = 1;
- unless ($tx->is_websocket) {
- say "Error: ".$tx->res->error; # Error: Premature connection close
- }
- $tx->on(message => sub {
- my ($tx, $message) = @_;
- say anydump($message);
- });
- $tx->send('hello'); # Can't locate object method "send" via package "Mojo::Transaction::HTTP"
- });
- Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
- #!/usr/bin/perl
- use strict;
- use warnings;
- use YAML::Syck;
- use JSON::XS;d
- use File::Slurp;
- use Scriptalicious;
- use Carp 'confess';
- use v5.18;
- use FindBin '$Bin';
- say "\n\n\nwe are $Bin/$0";
- use Mojolicious::Lite;
- my $ebug;
- websocket '/ebuge' => sub {
- my $self = shift;
- $self->app->log->info("WebSocket opened");
- my $output = sub {
- my ($return, $time) = @_;
- my ($stdout, $stderr) = $ebug->output;
- $self->tx->send(encode_json {
- line => $ebug->line,
- stdout => $stdout,
- stderr => $stderr,
- finished => $ebug->finished,
- package => $ebug->package,
- subroutine => $ebug->subroutine,
- line => $ebug->line,
- filename => $ebug->filename,
- code => $ebug->codeline,
- return => $return,
- });
- };
- $self->on(message => sub {
- my ($self, $msg) = @_;
- $self->app->log->info("WebSocket: $msg");
- if ($msg =~ /hello/) {
- start_timer();
- $ebug = _load();
- my $time = show_delta();
- $output->(undef, $time);
- }
- elsif ($msg =~ /exec (.+)/) {
- my $command = $1;
- start_timer();
- my $return = $ebug->$command();
- my $time = show_delta();
- $output->($return, $time);
- }
- });
- $self->on(finish => sub {
- my ($self, $code, $reason) = @_;
- $self->app->log->debug("WebSocket closed with status $code.");
- });
- };
- sub _load {
- my $ebug = Devel::ebug->new;
- $ebug->program('test/stylehouse.pl');
- $ebug->load;
- # litter it with places to wait
- # might even need a middleware so we can consider the jam instead of just jamming
- my @filenames = $ebug->filenames();
- @filenames = grep { /^lib|stylehouse\.pl$/ } @filenames;
- for my $filename (@filenames) {
- my $code = capture("cat $filename");
- my @codelines = split "\n", $code;
- my $line = 0;
- for my $codeline (@codelines) {
- if ($codeline =~ /my \$self = shift;/) {
- $ebug->break_point($filename, $line);
- }
- $line++;
- }
- }
- }
- my $daemon = Mojo::Server::Daemon->new(app => app, listen => ['http://localhost:4005']);
- $daemon->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement