Permalink
Browse files

Add a quick round of documentation, and edit some code and examples f…

…or brevity.
  • Loading branch information...
1 parent 334c0b8 commit 6a40b550e077a4abe09b2ea0d047b53e15c32945 @rcaputo committed Sep 23, 2009
View
@@ -0,0 +1,22 @@
+CHANGES
+MANIFEST
+META.yml
+Makefile.PL
+README
+lib/Reflex.pm
+lib/Reflex/Handle.pm
+lib/Reflex/Object.pm
+lib/Reflex/PID.pm
+lib/Reflex/POE/Event.pm
+lib/Reflex/POE/Postback.pm
+lib/Reflex/POE/Session.pm
+lib/Reflex/POE/Wheel.pm
+lib/Reflex/POE/Wheel/Run.pm
+lib/Reflex/Role/Object.pm
+lib/Reflex/Role/UdpPeer.pm
+lib/Reflex/Signal.pm
+lib/Reflex/Timer.pm
+lib/Reflex/Trait/Emitter.pm
+lib/Reflex/Trait/Observer.pm
+lib/Reflex/UdpPeer.pm
+t/00_info.t
View
@@ -0,0 +1,33 @@
+use ExtUtils::MakeMaker;
+
+# Touch auto-generated files so we don't see warnings.
+open(CHANGES, ">>CHANGES") and close CHANGES;
+open(README, ">>README") and close README;
+
+WriteMakefile(
+ NAME => 'Reflex',
+ AUTHOR => 'Rocco Caputo <rcaputo@cpan.org>',
+ ABSTRACT => 'Reactive classes for flexible programs.',
+ LICENSE => 'perl',
+ VERSION_FROM => 'lib/Reflex.pm',
+ PREREQ_PM => {
+ 'Scalar::Util' => 1.21,
+ 'POE' => 1.268,
+ 'Test::More' => 0.94,
+ 'Moose' => 0.92,
+ },
+ META_ADD => {
+ resources => {
+ license => 'http://dev.perl.org/licenses/',
+ repository => 'http://github.com/rcaputo/poe-stage/',
+ },
+ },
+ dist => {
+ COMPRESS => 'gzip -9f',
+ SUFFIX => 'gz',
+ PREOP => (
+ 'git-log.pl | tee ./$(DISTNAME)-$(VERSION)/CHANGES > ./CHANGES;' .
+ 'LANG=C perldoc lib/Reflex.pm > README'
+ ),
+ },
+);
@@ -14,25 +14,20 @@
extends 'Reflex::Object';
use Reflex::UdpPeer;
- has peer => (
- isa => 'Reflex::UdpPeer|Undef',
- is => 'rw',
+ has port => (
+ isa => 'Int',
+ is => 'ro',
);
- sub BUILD {
- my ($self, $args) = @_;
- $self->peer(
- Reflex::UdpPeer->new(
- port => $args->{port},
- observers => [
- {
- observer => $self,
- role => 'peer',
- }
- ]
- )
- );
- }
+ has peer => (
+ isa => 'Reflex::UdpPeer|Undef',
+ is => 'rw',
+ traits => ['Reflex::Trait::Observer'],
+ setup => sub {
+ my $self = shift;
+ Reflex::UdpPeer->new(port => $self->port());
+ },
+ );
sub on_peer_datagram {
my ($self, $args) = @_;
View
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+
+use lib qw(lib);
+
+{
+ package UdpPeer;
+
+ use Moose;
+ extends 'Reflex::Object';
+ use Reflex::Handle;
+
+ has port => (
+ isa => 'Int',
+ is => 'ro',
+ );
+
+ has handle => (
+ isa => 'Reflex::Handle|Undef',
+ is => 'rw',
+ traits => ['Reflex::Trait::Observer'],
+ role => 'remote',
+ );
+
+ after 'BUILD' => sub {
+ my $self = shift;
+
+ $self->handle(
+ Reflex::Handle->new(
+ handle => IO::Socket::INET->new(
+ Proto => 'udp',
+ LocalPort => $self->port(),
+ ),
+ rd => 1,
+ )
+ );
+ undef;
+ };
+
+ sub on_remote_read {
+ my ($self, $args) = @_;
+
+ my $remote_address = recv(
+ $args->{handle},
+ my $datagram = "",
+ 16384,
+ 0
+ );
+
+ if ($datagram =~ /^\s*quit\s*$/i) {
+ $self->handle(undef);
+ return;
+ }
+
+ return if send(
+ $args->{handle},
+ $datagram,
+ 0,
+ $remote_address,
+ ) == length($datagram);
+ }
+}
+
+exit UdpPeer->new( port => 12345 )->run_all();
View
@@ -8,26 +8,26 @@ use Carp qw(croak);
our $VERSION = '0.001';
sub import {
- my $class = shift;
- my $caller_package = caller();
-
- # Use the packages in the caller's package.
- # TODO - I think lexical magic isn't supported.
-
- eval join(
- "; ",
- "package $caller_package",
- map { "use $class\::$_" }
- @_
- );
-
-
- # Rewrite the error so that it comes from the caller.
- if ($@) {
- my $msg = $@;
- $msg =~ s/(\(\@INC contains.*?\)) at .*/$1/s;
- croak $msg;
- }
+ my $class = shift;
+ my $caller_package = caller();
+
+ # Use the packages in the caller's package.
+ # TODO - I think lexical magic isn't supported.
+
+ eval join(
+ "; ",
+ "package $caller_package",
+ map { "use $class\::$_" }
+ @_
+ );
+
+
+ # Rewrite the error so that it comes from the caller.
+ if ($@) {
+ my $msg = $@;
+ $msg =~ s/(\(\@INC contains.*?\)) at .*/$1/s;
+ croak $msg;
+ }
}
1;
@@ -40,64 +40,108 @@ Reflex - Reactive classes for flexible programs.
=head1 SYNOPSIS
- {
- package App;
- use Moose;
- extends 'Reflex::Object';
- use Reflex::Timer;
+ {
+ package App;
+ use Moose;
+ extends 'Reflex::Object';
+ use Reflex::Timer;
- has ticker => (
- isa => 'Reflex::Timer',
- is => 'rw',
- setup => { interval => 1, auto_repeat => 1 },
- traits => [ 'Reflex::Trait::Observer' ],
- );
+ has ticker => (
+ isa => 'Reflex::Timer',
+ is => 'rw',
+ setup => { interval => 1, auto_repeat => 1 },
+ traits => [ 'Reflex::Trait::Observer' ],
+ );
- sub on_ticker_tick {
- print "tick at ", scalar(localtime), "...\n";
- }
- }
+ sub on_ticker_tick {
+ print "tick at ", scalar(localtime), "...\n";
+ }
+ }
- exit App->new()->run_all();
+ exit App->new()->run_all();
=head1 DESCRIPTION
Reflex is a suite of classes to help programmers write reactive
-programs. More to come
+programs. The project has some goals:
+
+=over 2
+
+=item * Be concise.
+
+=item * Be convenient.
+
+=item * Be portable.
+
+=item * Be fast.
+
+=item * Don't get in the way.
+
+=item * Release early, and release often.
+
+=back
+
+Sorry for the lack of documentation. It conflicted with releasing
+early. Contributions are very much welcome. Give the project a
+reason to release often.
+
+TODO - Complete the documentation.
=head1 GETTING HELP
-POE's mailing list.
-Channel #poe on irc.perl.org.
+See irc.perl.org #moose for help with Moose.
+
+See irc.perl.org #poe for help with POE and Reflex.
+
+Support is officially available from POE's mailing list as well. Send
+a blank message to
+L<poe-subscribe@perl.org|mailto:poe-subscribe@perl.org>
+to join.
=head1 ACKNOWLEDGEMENTS
-irc.perl.org channel #moose and #poe. The former for assisting in
-learning their fine libraries, sometimes against everyone's better
-judgement. The latter for putting up with lengthy and sometimes
-irrelevant design discussion for oh so long.
+irc.perl.org channel
+L<#moose|irc://irc.perl.org/moose>
+and
+L<#poe|irc://irc.perl.org/moose>.
+The former for assisting in learning their fine libraries, sometimes
+against everyone's better judgement. The latter for putting up with
+lengthy and sometimes irrelevant design discussion for oh so long.
=head1 SEE ALSO
-Moose
-POE
-Ohlo
-Reflex namespace on CPAN.
-Links to tutorials & reviews.
-Home page for Reflex.
+L<Moose>, L<POE>, the Reflex namespace on CPAN.
+
+TODO - Set up ohlo.
+
+TODO - Set up CIA.
+
+TODO - Set up home page.
=head1 BUGS
-TODO - Link to Reflex's RT queue. Explain how to send e-mail, too.
+We appreciate your feedback, bug reports, feature requests, patches
+and kudos. You may enter them into our request tracker by following
+the instructions at
+L<https://rt.cpan.org/Dist/Display.html?&Queue=Reflex>.
+
+We also accept e-mail at
+L<bug-Reflex@rt.cpan.org|mailto:bug-Reflex@rt.cpan.org>.
=head1 AUTHORS
-Rocco Caputo
-Point out that it's a FOSS project, and anyone may contribute.
+Rocco Caputo, and a (hopefully) growing cadre of contributors---
+perhaps including you. Reflex is open source, and we welcome
+involvement.
=head2 OTHER CONTRIBUTORS
-List here, when there are some.
+Nobody yet. As of this writing, Reflex has not yet been released.
+
+=head1 TODO
+
+Please browse the source for the TODO marker. Some are visible in the
+documentation, and others are sprinlked around in the code's comments.
=head1 COPYRIGHT AND LICCENSE
@@ -106,6 +150,6 @@ Copyright 2009 by Rocco Caputo.
Reflex is free software. You may redistribute and/or modify it under
the same terms as Perl itself.
-TODO - Recommended best practice for licenses.
+TODO - Use the latest recommended best practice for licenses.
=cut
Oops, something went wrong.

0 comments on commit 6a40b55

Please sign in to comment.