Role-EventEmitter-0.003000755001750001750 013236377162 15041 5ustar00grinnzgrinnz000000000000README100644001750001750 656213236377162 16013 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003NAME Role::EventEmitter - Event emitter role SYNOPSIS package Channel; use Moo; with 'Role::EventEmitter'; # Emit events sub send_message { my $self = shift; $self->emit(message => @_); } package main; # Subscribe to events my $channel_a = Channel->new; $channel_a->on(message => sub { my ($channel, $text) = @_; say "Received message: $text"; }); $channel_a->send_message('All is well'); DESCRIPTION Role::EventEmitter is a simple Role::Tiny role for event emitting objects based on Mojo::EventEmitter. This role can be applied to any hash-based object class such as those created with Class::Tiny, Moo, or Moose. EVENTS Role::EventEmitter can emit the following events. error $e->on(error => sub { my ($e, $err) = @_; ... }); This is a special event for errors, it will not be emitted directly by this role but is fatal if unhandled. $e->on(error => sub { my ($e, $err) = @_; say "This looks bad: $err"; }); METHODS Role::EventEmitter composes the following methods. catch $e = $e->catch(sub {...}); Subscribe to "error" event. # Longer version $e->on(error => sub {...}); emit $e = $e->emit('foo'); $e = $e->emit('foo', 123); Emit event. has_subscribers my $bool = $e->has_subscribers('foo'); Check if event has subscribers. on my $cb = $e->on(foo => sub {...}); Subscribe to event. $e->on(foo => sub { my ($e, @args) = @_; ... }); once my $cb = $e->once(foo => sub {...}); Subscribe to event and unsubscribe again after it has been emitted once. $e->once(foo => sub { my ($e, @args) = @_; ... }); once_f my $f = $e->once_f('foo'); Subscribe to event as in "once", returning a Future that will be marked complete after it has been emitted once. Requires Future to be installed. my $f = $e->once_f('foo')->on_done(sub { my ($e, @args) = @_; ... }); To unsubscribe the returned Future early, cancel it. $f->cancel; subscribers my $subscribers = $e->subscribers('foo'); All subscribers for event. # Unsubscribe last subscriber $e->unsubscribe(foo => $e->subscribers('foo')->[-1]); # Change order of subscribers @{$e->subscribers('foo')} = reverse @{$e->subscribers('foo')}; unsubscribe $e = $e->unsubscribe('foo'); $e = $e->unsubscribe(foo => $cb); Unsubscribe from event. Related Futures will also be cancelled. DEBUGGING You can set the ROLE_EVENTEMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR. ROLE_EVENTEMITTER_DEBUG=1 BUGS Report any issues on the public bugtracker. AUTHOR Dan Book Code and tests adapted from Mojo::EventEmitter, an event emitter base class by the Mojolicious team. COPYRIGHT AND LICENSE Copyright (c) 2008-2015 Sebastian Riedel. Copyright (c) 2015 Dan Book for adaptation to a role and further changes. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) SEE ALSO Mojo::EventEmitter, Mixin::Event::Dispatch, Beam::Emitter, Event::Distributor Changes100644001750001750 36013236377162 16374 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.0030.003 2018-02-06 14:13:52 EST - Add once_f method to subscribe and return a Future 0.002 2015-10-27 21:22:12 EDT - Switch to Role::Tiny based role as attribute is not needed 0.001 2015-08-10 15:44:08 EDT - First release LICENSE100644001750001750 2151513236377162 16153 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003This software is Copyright (c) 2015 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. INSTALL100644001750001750 223613236377162 16156 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003This is the Perl distribution Role-EventEmitter. Installing Role-EventEmitter is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Role::EventEmitter If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Role::EventEmitter ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib ## Documentation Role-EventEmitter documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc Role::EventEmitter cpanfile100644001750001750 31013236377162 16600 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003requires 'perl' => '5.006'; requires 'Carp'; requires 'Role::Tiny' => '2.000001'; requires 'Scalar::Util'; test_requires 'Test::More' => '0.88'; test_requires 'Test::Needs'; author_requires 'Future'; dist.ini100644001750001750 34313236377162 16546 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003name = Role-EventEmitter author = Dan Book license = Artistic_2_0 copyright_holder = Dan Book copyright_year = 2015 [@Author::DBOOK] :version = 0.032 pod_tests = 1 Test::ReportPrereqs.include[] = Future META.yml100644001750001750 2665113236377162 16425 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003--- abstract: 'Event emitter role' author: - 'Dan Book ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Test::More: '0.88' Test::Needs: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010' license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Role-EventEmitter no_index: directory: - eg - examples - inc - share - t - xt provides: Role::EventEmitter: file: lib/Role/EventEmitter.pm version: '0.003' requires: Carp: '0' Role::Tiny: '2.000001' Scalar::Util: '0' perl: '5.006' resources: bugtracker: https://github.com/Grinnz/Role-EventEmitter/issues homepage: https://github.com/Grinnz/Role-EventEmitter repository: https://github.com/Grinnz/Role-EventEmitter.git version: '0.003' x_Dist_Zilla: perl: version: '5.026001' plugins: - class: Dist::Zilla::Plugin::GithubMeta name: '@Author::DBOOK/GithubMeta' version: '0.54' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Author::DBOOK/Readme_Github' version: '0.163250' - class: Dist::Zilla::Plugin::GenerateFile name: '@Author::DBOOK/Generate_Contrib' version: '6.010' - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::DBOOK/MetaConfig' version: '6.010' - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: finder_objects: - class: Dist::Zilla::Plugin::FinderCode name: '@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.010' include_underscores: 0 Dist::Zilla::Role::MetaProvider::Provider: $Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004' inherit_missing: '1' inherit_version: '1' meta_noindex: '1' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.004' name: '@Author::DBOOK/MetaProvides::Package' version: '2.004003' - class: Dist::Zilla::Plugin::Prereqs::FromCPANfile name: '@Author::DBOOK/Prereqs::FromCPANfile' version: '0.08' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: 2.14.3 include_authors: 0 include_releaser: 1 order_by: name paths: [] name: '@Author::DBOOK/Git::Contributors' version: '0.032' - class: Dist::Zilla::Plugin::MetaNoIndex name: '@Author::DBOOK/MetaNoIndex' version: '6.010' - class: Dist::Zilla::Plugin::CheckChangesHasContent name: '@Author::DBOOK/CheckChangesHasContent' version: '0.011' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.14.3 repo_root: . name: '@Author::DBOOK/Git::Check' version: '2.043' - class: Dist::Zilla::Plugin::RewriteVersion config: Dist::Zilla::Plugin::RewriteVersion: add_tarball_name: 0 finders: - ':ExecFiles' - ':InstallModules' global: 0 skip_version_provider: 0 name: '@Author::DBOOK/RewriteVersion' version: '0.017' - class: Dist::Zilla::Plugin::NextRelease name: '@Author::DBOOK/NextRelease' version: '6.010' - class: Dist::Zilla::Plugin::CopyFilesFromRelease config: Dist::Zilla::Plugin::CopyFilesFromRelease: filename: - CONTRIBUTING.md - INSTALL - LICENSE - META.json - Makefile.PL match: [] name: '@Author::DBOOK/CopyFilesFromRelease' version: '0.006' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: - / commit_msg: v%v%n%n%c Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - CONTRIBUTING.md - Changes - INSTALL - LICENSE - META.json - Makefile.PL - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.14.3 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Git::Commit' version: '2.043' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: v0.003 tag_format: v%v tag_message: v%v Dist::Zilla::Role::Git::Repo: git_version: 2.14.3 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Git::Tag' version: '2.043' - class: Dist::Zilla::Plugin::BumpVersionAfterRelease config: Dist::Zilla::Plugin::BumpVersionAfterRelease: finders: - ':ExecFiles' - ':InstallModules' global: 0 munge_makefile_pl: 0 name: '@Author::DBOOK/BumpVersionAfterRelease' version: '0.017' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: 'Bump version' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: - (?^:^(?:lib|script|bin)/) changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.14.3 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Commit_Version_Bump' version: '2.043' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 2.14.3 repo_root: . name: '@Author::DBOOK/Git::Push' version: '2.043' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::DBOOK/PodSyntaxTests' version: '6.010' - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Author::DBOOK/PodCoverageTests' version: '6.010' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@Author::DBOOK/Test::ReportPrereqs' version: '0.027' - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - Build.PL - CONTRIBUTING.md - INSTALL - LICENSE - META.json - Makefile.PL - Makefile.PL exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@Author::DBOOK/Git::GatherDir' version: '2.043' - class: Dist::Zilla::Plugin::Regenerate::AfterReleasers config: Dist::Zilla::Plugin::Regenerate::AfterReleasers: plugins: - '@Author::DBOOK/Readme_Github' - '@Author::DBOOK/CopyFilesFromRelease' Dist::Zilla::Role::Regenerator: $Dist::Zilla::Role::Regenerator::VERSION: '0.001001' name: '@Author::DBOOK/Regenerate::AfterReleasers' version: '0.001001' - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::DBOOK/PruneCruft' version: '6.010' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::DBOOK/ManifestSkip' version: '6.010' - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::DBOOK/MetaYAML' version: '6.010' - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::DBOOK/MetaJSON' version: '6.010' - class: Dist::Zilla::Plugin::License name: '@Author::DBOOK/License' version: '6.010' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Author::DBOOK/ReadmeAnyFromPod' version: '0.163250' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::DBOOK/ExecDir' version: '6.010' - class: Dist::Zilla::Plugin::ShareDir name: '@Author::DBOOK/ShareDir' version: '6.010' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::DBOOK/ScriptDir' version: '6.010' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::DBOOK/MakeMaker' version: '6.010' - class: Dist::Zilla::Plugin::RunExtraTests config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::DBOOK/RunExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::InstallGuide name: '@Author::DBOOK/InstallGuide' version: '1.200007' - class: Dist::Zilla::Plugin::Manifest name: '@Author::DBOOK/Manifest' version: '6.010' - class: Dist::Zilla::Plugin::TestRelease name: '@Author::DBOOK/TestRelease' version: '6.010' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::DBOOK/ConfirmRelease' version: '6.010' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Author::DBOOK/UploadToCPAN' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.010' - class: Dist::Zilla::Plugin::FinderCode name: '@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.010' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.010' x_contributors: - 'Dan Book ' x_serialization_backend: 'YAML::Tiny version 1.70' MANIFEST100644001750001750 51413236377162 16233 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. CONTRIBUTING.md Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/Role/EventEmitter.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/eventemitter.t t/future.t xt/author/pod-coverage.t xt/author/pod-syntax.t META.json100644001750001750 4326613236377162 16576 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003{ "abstract" : "Event emitter role", "author" : [ "Dan Book " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010", "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Role-EventEmitter", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Future" : "0", "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "0", "Role::Tiny" : "2.000001", "Scalar::Util" : "0", "perl" : "5.006" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Test::More" : "0.88", "Test::Needs" : "0" } } }, "provides" : { "Role::EventEmitter" : { "file" : "lib/Role/EventEmitter.pm", "version" : "0.003" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/Grinnz/Role-EventEmitter/issues" }, "homepage" : "https://github.com/Grinnz/Role-EventEmitter", "repository" : { "type" : "git", "url" : "https://github.com/Grinnz/Role-EventEmitter.git", "web" : "https://github.com/Grinnz/Role-EventEmitter" } }, "version" : "0.003", "x_Dist_Zilla" : { "perl" : { "version" : "5.026001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@Author::DBOOK/GithubMeta", "version" : "0.54" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Author::DBOOK/Readme_Github", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::GenerateFile", "name" : "@Author::DBOOK/Generate_Contrib", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::DBOOK/MetaConfig", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : { "finder_objects" : [ { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.010" } ], "include_underscores" : 0 }, "Dist::Zilla::Role::MetaProvider::Provider" : { "$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004", "inherit_missing" : 1, "inherit_version" : 1, "meta_noindex" : 1 }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.004" } }, "name" : "@Author::DBOOK/MetaProvides::Package", "version" : "2.004003" }, { "class" : "Dist::Zilla::Plugin::Prereqs::FromCPANfile", "name" : "@Author::DBOOK/Prereqs::FromCPANfile", "version" : "0.08" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.14.3", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [] } }, "name" : "@Author::DBOOK/Git::Contributors", "version" : "0.032" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "@Author::DBOOK/MetaNoIndex", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::CheckChangesHasContent", "name" : "@Author::DBOOK/CheckChangesHasContent", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.14.3", "repo_root" : "." } }, "name" : "@Author::DBOOK/Git::Check", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::RewriteVersion", "config" : { "Dist::Zilla::Plugin::RewriteVersion" : { "add_tarball_name" : 0, "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "skip_version_provider" : 0 } }, "name" : "@Author::DBOOK/RewriteVersion", "version" : "0.017" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@Author::DBOOK/NextRelease", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromRelease", "config" : { "Dist::Zilla::Plugin::CopyFilesFromRelease" : { "filename" : [ "CONTRIBUTING.md", "INSTALL", "LICENSE", "META.json", "Makefile.PL" ], "match" : [] } }, "name" : "@Author::DBOOK/CopyFilesFromRelease", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [ "/" ], "commit_msg" : "v%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "CONTRIBUTING.md", "Changes", "INSTALL", "LICENSE", "META.json", "Makefile.PL", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.14.3", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Git::Commit", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "v0.003", "tag_format" : "v%v", "tag_message" : "v%v" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.14.3", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Git::Tag", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::BumpVersionAfterRelease", "config" : { "Dist::Zilla::Plugin::BumpVersionAfterRelease" : { "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "munge_makefile_pl" : 0 } }, "name" : "@Author::DBOOK/BumpVersionAfterRelease", "version" : "0.017" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "Bump version" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [ "(?^:^(?:lib|script|bin)/)" ], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.14.3", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Commit_Version_Bump", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.14.3", "repo_root" : "." } }, "name" : "@Author::DBOOK/Git::Push", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::DBOOK/PodSyntaxTests", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Author::DBOOK/PodCoverageTests", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@Author::DBOOK/Test::ReportPrereqs", "version" : "0.027" }, { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "Build.PL", "CONTRIBUTING.md", "INSTALL", "LICENSE", "META.json", "Makefile.PL", "Makefile.PL" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@Author::DBOOK/Git::GatherDir", "version" : "2.043" }, { "class" : "Dist::Zilla::Plugin::Regenerate::AfterReleasers", "config" : { "Dist::Zilla::Plugin::Regenerate::AfterReleasers" : { "plugins" : [ "@Author::DBOOK/Readme_Github", "@Author::DBOOK/CopyFilesFromRelease" ] }, "Dist::Zilla::Role::Regenerator" : { "$Dist::Zilla::Role::Regenerator::VERSION" : "0.001001" } }, "name" : "@Author::DBOOK/Regenerate::AfterReleasers", "version" : "0.001001" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::DBOOK/PruneCruft", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::DBOOK/ManifestSkip", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::DBOOK/MetaYAML", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::DBOOK/MetaJSON", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::DBOOK/License", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Author::DBOOK/ReadmeAnyFromPod", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::DBOOK/ExecDir", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::DBOOK/ShareDir", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::DBOOK/ScriptDir", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::DBOOK/MakeMaker", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::RunExtraTests", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::DBOOK/RunExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@Author::DBOOK/InstallGuide", "version" : "1.200007" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::DBOOK/Manifest", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Author::DBOOK/TestRelease", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::DBOOK/ConfirmRelease", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Author::DBOOK/UploadToCPAN", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.010" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.010" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.010" } }, "x_contributors" : [ "Dan Book " ], "x_serialization_backend" : "Cpanel::JSON::XS version 4.00" } t000755001750001750 013236377162 15225 5ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003future.t100644001750001750 634013236377162 17067 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/tpackage My::EventEmitter; use Role::Tiny::With; with 'Role::EventEmitter'; sub new { bless {}, shift } package main; use strict; use warnings; use Test::More; use Test::Needs 'Future'; my $e = My::EventEmitter->new; # One-time event my $once; my $f = $e->once_f('one_time')->on_done(sub { $once++ }); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->unsubscribe(one_time => sub { }); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 1, 'event was emitted once'; is scalar @{$e->subscribers('one_time')}, 0, 'no subscribers'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; my $f2; $f = $e->once_f('one_time')->on_done(sub { $f2 = shift->once_f('one_time')->on_done(sub { $once++ }); }); $e->emit('one_time'); is $once, 1, 'event was emitted once'; $e->emit('one_time'); is $once, 2, 'event was emitted again'; $e->emit('one_time'); is $once, 2, 'event was not emitted again'; $f = $e->once_f('one_time')->on_done(sub { $once = shift->has_subscribers('one_time') }); $e->emit('one_time'); ok !$once, 'no subscribers'; # Nested one-time events $once = 0; my $f3; $f = $e->once_f('one_time') ->on_done(sub { $f2 = shift->once_f('one_time') ->on_done(sub { $f3 = shift->once_f('one_time')->on_done(sub { $once++ }); } ); } ); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 0, 'only first event was emitted'; is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 0, 'only second event was emitted'; is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 1, 'third event was emitted'; is scalar @{$e->subscribers('one_time')}, 0, 'no subscribers'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; # One-time event used directly $e = My::EventEmitter->new; ok !$e->has_subscribers('foo'), 'no subscribers'; $once = 0; $f = $e->once_f('foo')->on_done(sub { $once++ }); ok $e->has_subscribers('foo'), 'has subscribers'; $f->done; is $once, 1, 'event was emitted once'; ok !$e->has_subscribers('foo'), 'no subscribers'; # Cancel $e = My::EventEmitter->new; my $counter; $f = $e->once_f('foo')->on_done(sub { $counter++ }); $f->cancel; is scalar @{$e->subscribers('foo')}, 0, 'no subscribers'; $e->emit('foo'); is $counter, undef, 'event was not emitted'; # Unsubscribe $e = My::EventEmitter->new; $f = $e->once_f('foo')->on_done(sub { $counter++ }); $e->unsubscribe(foo => $e->subscribers('foo')->[0]); is scalar @{$e->subscribers('foo')}, 0, 'no subscribers'; ok $f->is_cancelled, 'future is cancelled'; $e->emit('foo'); is $counter, undef, 'event was not emitted'; # Unsubscribe all $e = My::EventEmitter->new; $f = $e->once_f('foo')->on_done(sub { $counter++ }); $e->unsubscribe('foo'); is scalar @{$e->subscribers('foo')}, 0, 'no subscribers'; ok $f->is_cancelled, 'future is cancelled'; $e->emit('foo'); is $counter, undef, 'event was not emitted'; done_testing(); Makefile.PL100644001750001750 241113236377162 17072 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.010. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Event emitter role", "AUTHOR" => "Dan Book ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Role-EventEmitter", "LICENSE" => "artistic_2", "MIN_PERL_VERSION" => "5.006", "NAME" => "Role::EventEmitter", "PREREQ_PM" => { "Carp" => 0, "Role::Tiny" => "2.000001", "Scalar::Util" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Test::More" => "0.88", "Test::Needs" => 0 }, "VERSION" => "0.003", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Role::Tiny" => "2.000001", "Scalar::Util" => 0, "Test::More" => "0.88", "Test::Needs" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); CONTRIBUTING.md100644001750001750 1043113236377162 17372 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003# HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla). This means that many of the usual files you might expect are not in the repository, but are generated at release time. Some generated files are kept in the repository as a convenience (e.g. Build.PL/Makefile.PL and META.json). Generally, **you do not need Dist::Zilla to contribute patches**. You may need Dist::Zilla to create a tarball. See below for guidance. ## Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use [cpanm](https://metacpan.org/pod/cpanm) to satisfy dependencies like this: $ cpanm --installdeps --with-develop . You can also run this command (or any other cpanm command) without installing App::cpanminus first, using the fatpacked `cpanm` script via curl or wget: $ curl -L https://cpanmin.us | perl - --installdeps --with-develop . $ wget -qO - https://cpanmin.us | perl - --installdeps --with-develop . Otherwise, look for either a `cpanfile` or `META.json` file for a list of dependencies to satisfy. ## Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ## Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. ## Installing and using Dist::Zilla [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ dzil authordeps --missing | cpanm You can use Dist::Zilla to install the distribution's dependencies if you haven't already installed them with cpanm: $ dzil listdeps --missing --develop | cpanm You can instead combine these two steps into one command by installing Dist::Zilla::App::Command::installdeps then running: $ dzil installdeps Once everything is installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil regenerate You can learn more about Dist::Zilla at http://dzil.org/ ## Other notes This distribution maintains the generated `META.json` and either `Makefile.PL` or `Build.PL` in the repository. This allows two things: [Travis CI](https://travis-ci.org/) can build and test the distribution without requiring Dist::Zilla, and the distribution can be installed directly from Github or a local git repository using `cpanm` for testing (again, not requiring Dist::Zilla). $ cpanm git://github.com/Author/Distribution-Name.git $ cd Distribution-Name; cpanm . Contributions are preferred in the form of a Github pull request. See [Using pull requests](https://help.github.com/articles/using-pull-requests/) for further information. You can use the Github issue tracker to report issues without an accompanying patch. # CREDITS This file was adapted from an initial `CONTRIBUTING.mkdn` file from David Golden under the terms of the Apache 2 license, with inspiration from the contributing documents from [Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING](https://metacpan.org/pod/Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING) and [Dist::Zilla::PluginBundle::Author::ETHER](https://metacpan.org/pod/Dist::Zilla::PluginBundle::Author::ETHER). eventemitter.t100644001750001750 1212013236377162 20301 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/tpackage My::EventEmitter; use Role::Tiny::With; with 'Role::EventEmitter'; sub new { bless {}, shift } package main; use strict; use warnings; use Test::More; # Normal event my $e = My::EventEmitter->new; my $called; $e->on(test1 => sub { $called++ }); $e->emit('test1'); is $called, 1, 'event was emitted once'; # Error $e->on(die => sub { die "works!\n" }); eval { $e->emit('die') }; is $@, "works!\n", 'right error'; # Unhandled error event eval { $e->emit(error => 'works') }; like $@, qr/^My::EventEmitter: works/, 'right error'; # Catch my $err; ok !$e->has_subscribers('foo'), 'no subscribers'; $e->catch(sub { $err = pop }); ok $e->has_subscribers('error'), 'has subscribers'; $e->emit(error => 'just works!'); is $err, 'just works!', 'right error'; # Exception in error event $e->once(error => sub { die "$_[1]entional" }); eval { $e->emit(error => 'int') }; like $@, qr/^intentional/, 'right error'; # Normal event again $e->emit('test1'); is $called, 2, 'event was emitted twice'; is scalar @{$e->subscribers('test1')}, 1, 'one subscriber'; $e->emit('test1'); $e->unsubscribe(test1 => $e->subscribers('test1')->[0]); is $called, 3, 'event was emitted three times'; is scalar @{$e->subscribers('test1')}, 0, 'no subscribers'; $e->emit('test1'); is $called, 3, 'event was not emitted again'; $e->emit('test1'); is $called, 3, 'event was not emitted again'; # One-time event my $once; $e->once(one_time => sub { $once++ }); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->unsubscribe(one_time => sub { }); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 1, 'event was emitted once'; is scalar @{$e->subscribers('one_time')}, 0, 'no subscribers'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->once( one_time => sub { shift->once(one_time => sub { $once++ }); } ); $e->emit('one_time'); is $once, 1, 'event was emitted once'; $e->emit('one_time'); is $once, 2, 'event was emitted again'; $e->emit('one_time'); is $once, 2, 'event was not emitted again'; $e->once(one_time => sub { $once = shift->has_subscribers('one_time') }); $e->emit('one_time'); ok !$once, 'no subscribers'; # Nested one-time events $once = 0; $e->once( one_time => sub { shift->once( one_time => sub { shift->once(one_time => sub { $once++ }); } ); } ); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 0, 'only first event was emitted'; is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 0, 'only second event was emitted'; is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); is $once, 1, 'third event was emitted'; is scalar @{$e->subscribers('one_time')}, 0, 'no subscribers'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; # One-time event used directly $e = My::EventEmitter->new; ok !$e->has_subscribers('foo'), 'no subscribers'; $once = 0; my $cb = $e->once(foo => sub { $once++ }); ok $e->has_subscribers('foo'), 'has subscribers'; $cb->(); is $once, 1, 'event was emitted once'; ok !$e->has_subscribers('foo'), 'no subscribers'; # Unsubscribe $e = My::EventEmitter->new; my $counter; $cb = $e->on(foo => sub { $counter++ }); $e->on(foo => sub { $counter++ }); $e->on(foo => sub { $counter++ }); $e->unsubscribe(foo => $e->once(foo => sub { $counter++ })); is scalar @{$e->subscribers('foo')}, 3, 'three subscribers'; $e->emit('foo')->unsubscribe(foo => $cb); is $counter, 3, 'event was emitted three times'; is scalar @{$e->subscribers('foo')}, 2, 'two subscribers'; $e->emit('foo'); is $counter, 5, 'event was emitted two times'; ok $e->has_subscribers('foo'), 'has subscribers'; ok !$e->unsubscribe('foo')->has_subscribers('foo'), 'no subscribers'; is scalar @{$e->subscribers('foo')}, 0, 'no subscribers'; $e->emit('foo'); is $counter, 5, 'event was not emitted again'; # Manipulate events $e = My::EventEmitter->new; my $buffer = ''; push @{$e->subscribers('foo')}, sub { $buffer .= 'one' }; push @{$e->subscribers('foo')}, sub { $buffer .= 'two' }; push @{$e->subscribers('foo')}, sub { $buffer .= 'three' }; $e->emit('foo'); is $buffer, 'onetwothree', 'right result'; @{$e->subscribers('foo')} = reverse @{$e->subscribers('foo')}; $e->emit('foo'); is $buffer, 'onetwothreethreetwoone', 'right result'; # Pass by reference and assignment to $_ $e = My::EventEmitter->new; $buffer = ''; $e->on(one => sub { $_ = $_[1] .= 'abc' . $_[2] }); $e->on(one => sub { $_[1] .= '123' . pop }); is $buffer, '', 'no result'; $e->emit(one => $buffer => 'two'); is $buffer, 'abctwo123two', 'right result'; $e->once(one => sub { $_[1] .= 'def' }); $e->emit(one => $buffer => 'three'); is $buffer, 'abctwo123twoabcthree123threedef', 'right result'; $e->emit(one => $buffer => 'x'); is $buffer, 'abctwo123twoabcthree123threedefabcx123x', 'right result'; done_testing(); 00-report-prereqs.t100644001750001750 1343613236377162 21010 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( Future ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: author000755001750001750 013236377162 16717 5ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/xtpod-syntax.t100644001750001750 25213236377162 21331 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100644001750001750 265013236377162 21110 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Future' => '0', 'Pod::Coverage::TrustPod' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Role::Tiny' => '2.000001', 'Scalar::Util' => '0', 'perl' => '5.006' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Test::More' => '0.88', 'Test::Needs' => '0' } } }; $x; }pod-coverage.t100644001750001750 33413236377162 21577 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Role000755001750001750 013236377162 16431 5ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/libEventEmitter.pm100644001750001750 1255313236377162 21570 0ustar00grinnzgrinnz000000000000Role-EventEmitter-0.003/lib/Rolepackage Role::EventEmitter; use Carp 'croak'; use Scalar::Util qw(blessed refaddr weaken); use constant DEBUG => $ENV{ROLE_EVENTEMITTER_DEBUG} || 0; use Role::Tiny; our $VERSION = '0.003'; sub catch { $_[0]->on(error => $_[1]) and return $_[0] } sub emit { my $self = shift; my $name = shift; if (my $s = $self->{_role_ee_events}{$name}) { warn "-- Emit $name in @{[blessed $self]} (@{[scalar @$s]})\n" if DEBUG; for my $cb (@$s) { $self->$cb(@_) } } else { warn "-- Emit $name in @{[blessed $self]} (0)\n" if DEBUG; die "@{[blessed $self]}: $_[0]" if $name eq 'error'; } return $self; } sub has_subscribers { !!$_[0]->{_role_ee_events}{$_[1]} } sub on { push @{$_[0]{_role_ee_events}{$_[1]}}, $_[2] and return $_[2] } sub once { my ($self, $name, $cb) = @_; weaken $self; my $wrapper; $wrapper = sub { $self->unsubscribe($name => $wrapper); $cb->(@_); }; $self->on($name => $wrapper); weaken $wrapper; return $wrapper; } my $has_future; sub once_f { my ($self, $name) = @_; unless (defined $has_future) { local $@; eval { require Future; $has_future = 1 } or $has_future = 0; } croak "Future is required for once_f method" unless $has_future; my $f = Future->new; my $wrapper = sub { $f->done(@_) }; $self->on($name => $wrapper); $self->{_role_ee_futures}{$name}{refaddr $wrapper} = $f; weaken $self; weaken $wrapper; return $f->on_ready(sub { $self->unsubscribe($name => $wrapper) }); } sub subscribers { $_[0]->{_role_ee_events}{$_[1]} ||= [] } sub unsubscribe { my ($self, $name, $cb) = @_; if ($cb) { # One my $addr = refaddr $cb; $self->{_role_ee_events}{$name} = [grep { $addr != refaddr $_ } @{$self->{_role_ee_events}{$name}}]; delete $self->{_role_ee_events}{$name} unless @{$self->{_role_ee_events}{$name}}; if ($self->{_role_ee_futures}{$name} and my $f = delete $self->{_role_ee_futures}{$name}{$addr}) { $f->cancel; delete $self->{_role_ee_futures}{$name} unless keys %{$self->{_role_ee_futures}{$name}}; } } else { # All delete $self->{_role_ee_events}{$name}; $_->cancel for values %{delete $self->{_role_ee_futures}{$name} || {}}; } return $self; } 1; =head1 NAME Role::EventEmitter - Event emitter role =head1 SYNOPSIS package Channel; use Moo; with 'Role::EventEmitter'; # Emit events sub send_message { my $self = shift; $self->emit(message => @_); } package main; # Subscribe to events my $channel_a = Channel->new; $channel_a->on(message => sub { my ($channel, $text) = @_; say "Received message: $text"; }); $channel_a->send_message('All is well'); =head1 DESCRIPTION L is a simple L role for event emitting objects based on L. This role can be applied to any hash-based object class such as those created with L, L, or L. =head1 EVENTS L can emit the following events. =head2 error $e->on(error => sub { my ($e, $err) = @_; ... }); This is a special event for errors, it will not be emitted directly by this role but is fatal if unhandled. $e->on(error => sub { my ($e, $err) = @_; say "This looks bad: $err"; }); =head1 METHODS L composes the following methods. =head2 catch $e = $e->catch(sub {...}); Subscribe to L event. # Longer version $e->on(error => sub {...}); =head2 emit $e = $e->emit('foo'); $e = $e->emit('foo', 123); Emit event. =head2 has_subscribers my $bool = $e->has_subscribers('foo'); Check if event has subscribers. =head2 on my $cb = $e->on(foo => sub {...}); Subscribe to event. $e->on(foo => sub { my ($e, @args) = @_; ... }); =head2 once my $cb = $e->once(foo => sub {...}); Subscribe to event and unsubscribe again after it has been emitted once. $e->once(foo => sub { my ($e, @args) = @_; ... }); =head2 once_f my $f = $e->once_f('foo'); Subscribe to event as in L, returning a L that will be marked complete after it has been emitted once. Requires L to be installed. my $f = $e->once_f('foo')->on_done(sub { my ($e, @args) = @_; ... }); To unsubscribe the returned L early, cancel it. $f->cancel; =head2 subscribers my $subscribers = $e->subscribers('foo'); All subscribers for event. # Unsubscribe last subscriber $e->unsubscribe(foo => $e->subscribers('foo')->[-1]); # Change order of subscribers @{$e->subscribers('foo')} = reverse @{$e->subscribers('foo')}; =head2 unsubscribe $e = $e->unsubscribe('foo'); $e = $e->unsubscribe(foo => $cb); Unsubscribe from event. Related Futures will also be cancelled. =head1 DEBUGGING You can set the C environment variable to get some advanced diagnostics information printed to C. ROLE_EVENTEMITTER_DEBUG=1 =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book Code and tests adapted from L, an event emitter base class by the L team. =head1 COPYRIGHT AND LICENSE Copyright (c) 2008-2015 Sebastian Riedel. Copyright (c) 2015 Dan Book for adaptation to a role and further changes. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =head1 SEE ALSO L, L, L, L