Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ævar Arnfjörð Bjarmason
committed
Feb 20, 2008
0 parents
commit e938523
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lib/POE/Filter/Swank.pm | ||
Makefile.PL | ||
MANIFEST This list of files | ||
MANIFEST.SKIP | ||
t/00-compile.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
^\.git/ | ||
^blib | ||
^Makefile$ | ||
^pm_to_blib$ | ||
\.bak$ | ||
\.old$ | ||
\.tar$ | ||
\.tar\.gz$ | ||
~$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use strict; | ||
use ExtUtils::MakeMaker; | ||
|
||
WriteMakefile( | ||
NAME => 'POE::Filter::Swank', | ||
AUTHOR => 'Ævar Arnfjörð Bjarmason <avar@cpan.org>', | ||
ABSTRACT_FROM => 'lib/POE/Filter/Swank.pm', | ||
VERSION_FROM => 'lib/POE/Filter/Swank.pm', | ||
LICENSE => 'perl', | ||
PREREQ_PM => { | ||
# Client.pm | ||
'POE' => '0.9999', | ||
|
||
# t/ | ||
'Test::More' => 0, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# This code was adapted from POE::Filter::Stream by Rocco | ||
package POE::Filter::Swank; | ||
use strict; | ||
use warnings; | ||
use bytes (); | ||
use POE::Filter; | ||
|
||
our @ISA = ('POE::Filter'); | ||
our $VERSION = '0.01'; | ||
|
||
sub new | ||
{ | ||
my $type = shift; | ||
my $buffer = ''; | ||
my $self = bless \$buffer, $type; | ||
$self; | ||
} | ||
|
||
sub clone | ||
{ | ||
my $self = shift; | ||
my $buffer = ''; | ||
my $clone = bless \$buffer, ref $self; | ||
} | ||
|
||
sub get_one_start | ||
{ | ||
my ($self, $stream) = @_; | ||
$$self .= join '', @$stream; | ||
} | ||
|
||
sub get_one | ||
{ | ||
my $self = shift; | ||
return [ ] unless length $$self; | ||
my $chunk = $$self; | ||
$$self = ''; | ||
|
||
my $length = hex bytes::substr $chunk, 0, 6; | ||
my $content = bytes::substr $chunk, 6, $length; | ||
|
||
[ $content ]; | ||
} | ||
|
||
sub put | ||
{ | ||
my ($self, $chunks) = @_; | ||
|
||
my $length = sprintf "%06x", bytes::length join '', @$chunks; | ||
|
||
[ $length, @$chunks ]; | ||
} | ||
|
||
sub get_pending | ||
{ | ||
my $self = shift; | ||
return [ $$self ] if length $$self; | ||
undef; | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 NAME | ||
POE::Filter::Swank - Stream based filter for the Swank protocol | ||
=head1 DESCRIPTION | ||
The swank protocol is the protocol used by the Emacs part of SLIME to | ||
communicate with its Lisp part, the swank server. | ||
The protocol is a very simple stream based protocol where each message | ||
is preceded by its length, e.g. Emacs might send this message at the | ||
start of a SLIME session to get information about the Swank server: | ||
00002d(:emacs-rex (swank:connection-info) nil t 1) | ||
To which the swank server might reply: | ||
00038E(:return (:ok (:pid 16581 :style :spawn :lisp-implementation [ message truncated ] | ||
This filter takes care of stripping the length from incoming messages | ||
and adding them to your outgoing messages, leaving you to worry only | ||
about the sexps. | ||
=head1 AUTHOR | ||
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> | ||
=head1 LICENSE | ||
Copyright 2008 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason. | ||
This program is free software; you can redistribute it and/or modify it | ||
under the same terms as Perl itself. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use strict; | ||
use Test::More tests => 1; | ||
use_ok 'POE::Filter::Swank'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use strict; | ||
use Test::More tests => 2; | ||
use POE::Filter::Swank; | ||
|
||
my $swank = POE::Filter::Swank->new; | ||
|
||
is_deeply($swank->get(["000009greetings"]), [ 'greetings' ]); | ||
is_deeply($swank->put(["greetings"]), [ '000009', 'greetings' ]); | ||
|