Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use readme_frompod

  • Loading branch information...
commit c14e4d8393fecb7a745fca5bcd6b0f259bcbaf68 1 parent 242a6d6
@typester authored
Showing with 149 additions and 15 deletions.
  1. +1 −0  Makefile.PL
  2. +148 −15 README
View
1  Makefile.PL
@@ -4,6 +4,7 @@ assertos 'MacOSX';
name 'Cocoa-EventLoop';
all_from 'lib/Cocoa/EventLoop.pm';
+readme_from 'lib/Cocoa/EventLoop.pm';
test_requires 'Test::More' => '0.88';
test_requires 'Test::TCP' => '1.11';
View
163 README
@@ -1,27 +1,160 @@
-This is Perl module Cocoa::EventLoop.
+NAME
+ Cocoa::EventLoop - perl interface for Cocoa event loop.
-INSTALLATION
+SYNOPSIS
+ use Cocoa::EventLoop;
+
+ # on-shot timer
+ my $timer = Cocoa::EventLoop->timer(
+ after => 10,
+ cb => sub {
+ # do something
+ },
+ );
+
+ # repeatable timer
+ my $timer = Cocoa::EventLoop->timer(
+ after => 10,
+ interval => 10,
+ cb => sub {
+ # do something
+ },
+ );
+
+ # stop or cancel timers
+ undef $timer;
+
+
+ # I/O Watcher
+ my $io = Cocoa::EventLoop->io(
+ fh => *STDIN,
+ poll => 'r',
+ cb => sub {
+ warn 'read: ', <STDIN>;
+ },
+ );
+
+
+ # run main loop
+ Cocoa::EventLoop->run;
+
+ # run main loop for specified period.
+ Cocoa::EventLoop->run_while($secs);
-Cocoa::EventLoop installation is straightforward. If your CPAN shell is set up,
-you should just be able to do
+DESCRIPTION
+ This module provides perl interface for Cocoa's event loop, NSRunLoop.
+ And also provides some timers and io watchers within the loop.
- % cpan Cocoa::EventLoop
+ If you want to use or write some modules that depends Cocoa event loop,
+ using this module is easiest way. For example, Cocoa::Growl is possible
+ to handle click event when it runs with this module:
-Download it, unpack it, then build it as per the usual:
+ use Cocoa::EventLoop;
+ use Cocoa::Growl;
+
+ my $done = 0;
+ growl_notify(
+ name => 'Notification Name',
+ title => 'Hello',
+ description => 'Cocoa World!',
+ on_click => sub {
+ $done++;
+ },
+ on_timeout => sub {
+ $done++;
+ },
+ );
+
+ Cocoa::EventLoop->run_while(0.1) while !$done;
- % perl Makefile.PL
- % make && make test
+ If you write more complicated script, consider using
+ AnyEvent::Impl::NSRunLoop instead of using this module directly.
+ AnyEvent::Impl::NSRunLoop is a wrapper for Cocoa::EventLoop and
+ AnyEvent. If you use AnyEvent::Impl::NSRunLoop, you can use any AnyEvent
+ based modules in Cocoa's event loop.
-Then install it:
+CLASS METHODS
+ Cocoa::EventLoop->timer(%parameters)
+ $timer = Cocoa::EventLoop->timer(after => <seconds>, cb => <callback>);
+
+ $timer = Cocoa::EventLoop->timer(
+ after => <fractional_seconds>,
+ interval => <fractional_seconds>,
+ cb => <callback>,
+ );
- % make install
+ Create one-shot or repeat timer.
-DOCUMENTATION
+ Available parameters are:
-Cocoa::EventLoop documentation is available as in POD. So you can do:
+ * after => 'Number'
- % perldoc Cocoa::EventLoop
+ How many seconds (fractional values are supported) the callback
+ should be invoked. When this value does not specified, use 0 by
+ default.
-to read the documentation online with your favorite pager.
+ * interval => 'Number'
+
+ Callback will be invoked regularly at this interval (in fractional
+ seconds) after the first invocation. If this value does not
+ specified, use 0 by default (== act as non repeat, on-shot timer);
+
+ * cb => 'CodeRef'
+
+ Callbacks that will be invoked when timer is fire. This parameter is
+ required.
+
+ Cocoa::EventLoop->io(%parameters)
+ $io = Cocoa::EventLoop->io(
+ fh => <filehandle_or_fileno>,
+ poll => <"r" or "w">,
+ cb => <callback>,
+ );
+
+ Create I/O watcher. Available parameters are:
+
+ * fh => 'FileHandle' or fileno
+
+ Perl file handle (or a naked file descriptor) to watch for events.
+ (Required)
+
+ * poll => 'r' or 'w'
+
+ Type for watching event. 'r' is for readable, 'w' is for writable.
+ (Required)
+
+ * cb => 'CodeRef'
+
+ callback to invoke each time the file handle becomes ready.
+ (Required)
+
+ Cocoa::EventLoop->run
+ Start Cocoa main loop.
+
+ This method exits immediately when no input sources or timers are
+ attached to the loop, but Mac OS X can install and remove additional
+ input sources as needed, and those sources could therefore prevent the
+ run loop from exiting.
+
+ If you want the run loop to terminate, you shouldn't use this method.
+ Instead, use one of the other run methods and also check other arbitrary
+ conditions of your own, in a loop. A simple example would be:
+
+ my $should_keep_running = 0; # global
+ Cocoa::EventLoop->run_while(0.1) while $should_keep_running;
+
+ Cocoa::EventLoop->run_while($secs)
+ Run Cocoa main loop only while specified seconds.
+
+AUTHOR
+ Daisuke Murase <typester@cpan.org>
+
+COPYRIGHT AND LICENSE
+ Copyright (c) 2009 by KAYAC Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the same terms as Perl itself.
+
+ The full text of the license can be found in the LICENSE file included
+ with this module.
-Daisuke Murase
Please sign in to comment.
Something went wrong with that request. Please try again.