| 1 | package Net::GPSD3::POE; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use base qw{Net::GPSD3}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use POE::Session; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use POE::Wheel::ReadWrite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use POE::Filter::Line; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use POE::Kernel; #exports $poe_kernel | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION='0.17'; | |||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Net::GPSD3::POE - Net::GPSD3 POE Session object | ||||||||||
| 15 | |||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||
| 17 | |||||||||||
| 18 | use POE; | ||||||||||
| 19 | use Net::GPSD3::POE; | ||||||||||
| 20 | my $gpsd=Net::GPSD3::POE->new; | ||||||||||
| 21 | #$gpsd->addHandler; | ||||||||||
| 22 | $gpsd->session; | ||||||||||
| 23 | #other POE::Sessions... | ||||||||||
| 24 | POE::Kernel->run; | ||||||||||
| 25 | |||||||||||
| 26 | One Liner | ||||||||||
| 27 | |||||||||||
| 28 | perl -MPOE -MNet::GPSD3::POE -e 'Net::GPSD3::POE->new->session;POE::Kernel->run;' | ||||||||||
| 29 | |||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||
| 31 | |||||||||||
| 32 | This package adds a L<POE::Session> capabilty to Net::GPSD3. | ||||||||||
| 33 | |||||||||||
| 34 | =head1 METHODS | ||||||||||
| 35 | |||||||||||
| 36 | =head2 session | ||||||||||
| 37 | |||||||||||
| 38 | Configures and returns the POE::Session ID | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub session { | ||||||||
|
Subroutine
session: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 43 | 0 | my $self=shift; #ISA Net::GPSD::POE | |||||||||
| 44 | $self->{"session"}=POE::Session->create( | ||||||||||
| 45 | object_states => [ | ||||||||||
| 46 | $self => { | ||||||||||
| 47 | _start => '_session_start', | ||||||||||
| 48 | _stop => '_session_stop', | ||||||||||
| 49 | shutdown => '_session_shutdown', | ||||||||||
| 50 | input_event => '_event_handler', | ||||||||||
| 51 | pause => 'pause', | ||||||||||
| 52 | resume => 'resume', | ||||||||||
| 53 | 0 | ▶ | }])->ID unless $self->{"session"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return $self->{"session"}; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub _session_start { | ||||||||
|
Subroutine
_session_start: not called CC=1 SCAR=6.9
| |||||||||||
| 58 | 0 | my $self=shift; | |||||||||
| 59 | 0 | $self->{"wheel"}=POE::Wheel::ReadWrite->new( | |||||||||
| 60 | InputEvent => "input_event", | ||||||||||
| 61 | Handle => $self->socket, | ||||||||||
| 62 | Filter => POE::Filter::Line->new( | ||||||||||
| 63 | InputLiteral => "\r\n", | ||||||||||
| 64 | OutputLiteral => "\n", | ||||||||||
| 65 | ), | ||||||||||
| 66 | ); | ||||||||||
| 67 | 0 | $self->resume; | |||||||||
| 68 | 0 | return $self; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head2 resume | ||||||||||
| 72 | |||||||||||
| 73 | Resumes or starts the watcher stream but not the socket | ||||||||||
| 74 | |||||||||||
| 75 | =cut | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub resume { | ||||||||
|
Subroutine
resume: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 78 | 0 | my $self=shift; | |||||||||
| 79 | 0 | ▶ | if ($self->{"wheel"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | $self->{"wheel"}->put($self->_watch_string_on); | |||||||||
| 81 | 0 | ▶ | delete $self->{"paused"} if exists $self->{"paused"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | } | ||||||||||
| 83 | 0 | return $self; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | =head2 pause | ||||||||||
| 87 | |||||||||||
| 88 | Pauses or turns off the watcher stream but not the socket | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub pause { | ||||||||
|
Subroutine
pause: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 93 | 0 | my $self=shift; | |||||||||
| 94 | 0 | ▶ | unless ($self->{"paused"}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | $self->{"wheel"}->put($self->_watch_string_off) | ||||||||||
| 96 | 0 | ▶ | if $self->{"wheel"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | $self->{"paused"}=1; #Should we get this from the WATCH return? | |||||||||
| 98 | } | ||||||||||
| 99 | 0 | return $self; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | sub _session_stop { | ||||||||
|
Subroutine
_session_stop: not called CC=2 SCAR=17.9
| |||||||||||
| 103 | 0 | my $self=shift; | |||||||||
| 104 | $poe_kernel->call($self->{"session"}, "shutdown") | ||||||||||
| 105 | 0 | ▶ | if $self->{"session"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 0 | return $self; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 0 | ▶ | sub _session_shutdown { | ||||||||
|
Subroutine
_session_shutdown: not called CC=1 SCAR=6.9
| |||||||||||
| 110 | 0 | my $self=$_[OBJECT]; | |||||||||
| 111 | 0 | return delete $self->{"wheel"}; | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 0 | ▶ | sub _event_handler { | ||||||||
|
Subroutine
_event_handler: not called CC=3 SCAR=24.8
| |||||||||||
| 115 | 0 | my ($self, $line)=@_[OBJECT, ARG0]; | |||||||||
| 116 | 0 | my @handler=$self->handlers; | |||||||||
| 117 | 0 | ▶ | push @handler, \&Net::GPSD3::default_handler unless scalar(@handler); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 0 | my $object=$self->constructor($self->decode($line), string=>$line); | |||||||||
| 119 | 0 | $_->($object) foreach @handler; | |||||||||
| 120 | 0 | $self->cache($object); | |||||||||
| 121 | 0 | return $self; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | =head1 BUGS | ||||||||||
| 125 | |||||||||||
| 126 | Log on RT and Send to gpsd-dev email list | ||||||||||
| 127 | |||||||||||
| 128 | =head1 SUPPORT | ||||||||||
| 129 | |||||||||||
| 130 | DavisNetworks.com supports all Perl applications including this package. | ||||||||||
| 131 | |||||||||||
| 132 | Try gpsd-dev email list | ||||||||||
| 133 | |||||||||||
| 134 | =head1 AUTHOR | ||||||||||
| 135 | |||||||||||
| 136 | Michael R. Davis | ||||||||||
| 137 | CPAN ID: MRDVT | ||||||||||
| 138 | STOP, LLC | ||||||||||
| 139 | domain=>michaelrdavis,tld=>com,account=>perl | ||||||||||
| 140 | http://www.stopllc.com/ | ||||||||||
| 141 | |||||||||||
| 142 | =head1 COPYRIGHT | ||||||||||
| 143 | |||||||||||
| 144 | This program is free software licensed under the... | ||||||||||
| 145 | |||||||||||
| 146 | The BSD License | ||||||||||
| 147 | |||||||||||
| 148 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||
| 149 | |||||||||||
| 150 | =head1 SEE ALSO | ||||||||||
| 151 | |||||||||||
| 152 | L<Net::GPSD3>, L<POE>, L<POE::Session>, L<POE::Wheel::ReadWrite>, L<POE::Filter::Line> | ||||||||||
| 153 | |||||||||||
| 154 | =cut | ||||||||||
| 155 | |||||||||||
| 156 | 1 | 1; | |||||||||