Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

separate notifier from writer

  • Loading branch information...
commit 83adc8026ce3e5a91127165844094d513d7d6082 1 parent 557bd83
Kazuhiro YOSHIKAWA authored

Showing 1 changed file with 11 additions and 16 deletions. Show diff stats Hide diff stats

  1. +11 16 clipboard_text_listener.pl
27 clipboard_text_listener.pl
@@ -23,22 +23,22 @@ package WriterFactory;
23 23 );
24 24 sub create {
25 25 my ($self, $type) = @_;
26   - my $notifier = _createNotifier();
27 26 if ($type eq 'clipboard') {
28 27 if ($^O =~ /^(MSWin32|cygwin)$/) {
29 28 eval { require Win32::Clipboard; };
30 29 unless ($@) {
31   - return Writer::Clipboard::Win32->new($notifier);
  30 + return Writer::Clipboard::Win32->new;
32 31 }
33 32 }
34 33 if (my $cmdline = _get_cmdline($command{$^O}->{clipboard})) {
35   - return Writer::Clipboard::Cmd->new($notifier, $cmdline);
  34 + return Writer::Clipboard::Cmd->new($cmdline);
36 35 }
37 36 }
38 37 print "Platform: $^O is not supported yet. echo received text only.\n";
39   - return Writer->new($notifier);
  38 + return Writer->new;
40 39 }
41   - sub _createNotifier {
  40 + sub createNotifier {
  41 + my ($self, $type) = @_;
42 42 if ($^O =~ /^(MSWin32|cygwin)$/) {
43 43 eval { require Win32::GUI; };
44 44 unless ($@) {
@@ -105,26 +105,21 @@ package Command;
105 105 package Writer;
106 106 {
107 107 sub new {
108   - my ($class, $notifier) = @_;
109   - return bless { notifier => $notifier }, $class;
  108 + my ($class) = @_;
  109 + return bless {}, $class;
110 110 }
111 111 sub write {
112 112 my ($self, $text) = @_;
113 113 print "$text\n";
114 114 }
115   - sub notify {
116   - my ($self, $info) = @_;
117   - $self->{notifier}->notify($info);
118   - }
119 115 }
120 116
121 117 package Writer::Clipboard::Win32;
122 118 use base qw(Writer);
123 119 {
124 120 sub new {
125   - my ($class, $notifier) = @_;
  121 + my ($class) = @_;
126 122 my $self = bless {
127   - notifier => $notifier,
128 123 clipboard => Win32::Clipboard(),
129 124 }, $class;
130 125 $self
@@ -139,9 +134,8 @@ package Writer::Clipboard::Cmd;
139 134 use base qw(Writer);
140 135 {
141 136 sub new {
142   - my ($class, $notifier, $cmdline) = @_;
  137 + my ($class, $cmdline) = @_;
143 138 my $self = bless {
144   - notifier => $notifier,
145 139 command => Command->new($cmdline),
146 140 }, $class;
147 141 $self
@@ -202,6 +196,7 @@ package TextWriter;
202 196 my ($class, $opts) = @_;
203 197 my $self = bless {
204 198 writer => {},
  199 + notifier => WriterFactory->createNotifier(),
205 200 encoding => $opts->{encoding},
206 201 verbose => $opts->{verbose},
207 202 nlength => $opts->{nlength} || 40,
@@ -227,7 +222,7 @@ package TextWriter;
227 222 print encode($self->{termenc}, decode($text_encoding, "$text\n"))
228 223 if ref $writer ne 'Writer';
229 224 }
230   - $writer->notify({
  225 + $self->{notifier}->notify({
231 226 title => sprintf('(%s) %s', length($enc_text), ref $writer),
232 227 text => substr($text, 0, $self->{nlength}),
233 228 enc_text => substr($enc_text, 0, $self->{nlength}), # for Win32

0 comments on commit 83adc80

Please sign in to comment.
Something went wrong with that request. Please try again.