| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | Coro::Channel::Factory - Factory for named Coro::Channel queues. | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||
| 6 | |||||||||||
| 7 | use Coro::Channel::Factory; | ||||||||||
| 8 | |||||||||||
| 9 | # Initialise factory | ||||||||||
| 10 | my $factory = Coro::Channel::Factory->new(); | ||||||||||
| 11 | |||||||||||
| 12 | # Get a handle to a (possibly previously undeclared) Coro::Channel, and put something.. | ||||||||||
| 13 | my $channel = $factory->name('some channel name'); | ||||||||||
| 14 | $channel->put($var); | ||||||||||
| 15 | |||||||||||
| 16 | # Interacting directly - no intermediate handle object.. | ||||||||||
| 17 | $factory->name('some channel name')->put($other_var); | ||||||||||
| 18 | my $item = $factory->name('some channel name')->get; | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | This module provides a very simple name-binding for Coro::Channel, removing the need to track individual Coro::Channel objects. | ||||||||||
| 23 | |||||||||||
| 24 | As long as the Coro::Channel::Factory object is available, any named Coro::Channel can be utilised. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | package Coro::Channel::Factory; | ||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | use 5.008002; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | use Coro; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 1 | our $VERSION = '1.01'; | |||||||||
| 37 | |||||||||||
| 38 | =head2 API | ||||||||||
| 39 | |||||||||||
| 40 | =over 4 | ||||||||||
| 41 | |||||||||||
| 42 | =item $factory = Coro::Channel::Factory->new() | ||||||||||
| 43 | |||||||||||
| 44 | Creates the Factory object | ||||||||||
| 45 | |||||||||||
| 46 | =back | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 51 | 0 | my $class = shift; | |||||||||
| 52 | |||||||||||
| 53 | 0 | my $self = {}; | |||||||||
| 54 | |||||||||||
| 55 | 0 | bless($self, $class); | |||||||||
| 56 | |||||||||||
| 57 | 0 | $self->initialise(@_); | |||||||||
| 58 | |||||||||||
| 59 | 0 | return $self; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub initialise { | ||||||||
|
Subroutine
initialise: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 63 | 0 | my $self = shift; | |||||||||
| 64 | |||||||||||
| 65 | 0 | $self->{channels} = { }; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | =over 4 | ||||||||||
| 69 | |||||||||||
| 70 | =item $channel = $factory->name($name) | ||||||||||
| 71 | |||||||||||
| 72 | Get or create a channel with name $name | ||||||||||
| 73 | |||||||||||
| 74 | =back | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub name { | ||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 79 | 0 | my $self = shift; | |||||||||
| 80 | 0 | my $channelName = shift; | |||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | if (!defined($self->{channels}->{$channelName})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | $self->{channels}->{$channelName} = new Coro::Channel; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | return $self->{channels}->{$channelName}; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | =head1 SEE ALSO | ||||||||||
| 90 | |||||||||||
| 91 | L<Coro> | ||||||||||
| 92 | L<Coro::Channel> | ||||||||||
| 93 | |||||||||||
| 94 | =head1 AUTHOR | ||||||||||
| 95 | |||||||||||
| 96 | Phillip O'Donnell, E<lt>podonnell@cpan.orgE<gt> | ||||||||||
| 97 | |||||||||||
| 98 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 99 | |||||||||||
| 100 | Copyright (C) 2013 by Phillip O'Donnell | ||||||||||
| 101 | |||||||||||
| 102 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 103 | it under the same terms as Perl itself, either Perl version 5.8.2 or, | ||||||||||
| 104 | at your option, any later version of Perl 5 you may have available. | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||
| 107 | |||||||||||
| 108 | 1 | 1; | |||||||||
| 109 | |||||||||||