Glue/Application.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 44 CC 3 SCAR 13.3
CC
3
Cov
0%
ref
6.0
objref
6.0
_init
2.0
CRAP 3.8
1 package Mac::AppleScript::Glue::Application;
2 $Mac::AppleScript::Glue::Application::VERSION = '0.06';
3 =head1 NAME
4  
5 Mac::AppleScript::Glue::Application - an application to send AppleScript to
6  
7  
8 =head1 VERSION
9  
10 version 0.06
11  
12 =head1 SYNOPSIS
13  
14 use Mac::AppleScript::Glue;
15 use Mac::AppleScript::Glue::Application;
16  
17 my $finder = new Mac::AppleScript::Glue::Application('Finder');
18  
19 my $version = $finder->version;
20  
21  
22 =head1 DESCRIPTION
23  
24 Objects of this module are used to send events to an application.
25  
26 See L<Mac::AppleScript::Glue> for full information on how to use this
27 package.
28  
29  
30 =cut
31  
32 ######################################################################
33  
34 use strict;
35 use warnings;
36  
37 use base qw(Mac::AppleScript::Glue::Object);
38  
39 ######################################################################
40 ######################################################################
41 # methods
42  
43 =head1 METHODS
44  
45 =over 4
46  
47 =cut
48  
49 ######################################################################
50  
51 =item new($app_name [, $machine ])
52  
53 Creates a new application object for the C<$app_name> application.
54  
55 If C<$machine> is specified, the specified computer will be sent
56 events instead of the local machine. This uses Apple Remote Events,
57 which you'll have to have enabled on the remote machine before events
58 can be sent to it. (Look in the B<Sharing> system preference or
59 control panel on the remote machine.)
60  
61 NOTE: Documentation on remote events is a little vague; it seems that
62 you specify the remote machine as a URL like C<< eppc://<host> >>,
63 where C<< <host> >> is either a hostname or IP address. "EPPC" stands
64 for Event Program to Program Communication, apparently.
65  
66 =cut
67  
68 # implemented via $AUTOLOAD
69  
70 ######################################################################
71  
72 sub _init {
73 my ($self, $args) = @_;
74  
75 $self->{_app_name} = shift @$args;
76 $self->{_machine} = shift @$args;
77  
78 return $self->SUPER::_init($args);
79 }
80  
81 ######################################################################
82  
83 =item app_name
84  
85 Returns the name of the application connected to this object.
86  
87 =cut
88  
89 # implemented via $AUTOLOAD
90  
91 ######################################################################
92  
93 =item ref
94  
95 Returns the AppleScript object reference for this application.
96  
97 =cut
98  
99 sub ref {
100 my ($self) = @_;
101  
102 my $ref = 'application "' . $self->app_name . '"';
103  
104 if ($self->machine) {
105 $ref .= ' of machine "' . $self->machine . '"';
106 }
107  
108 return $ref;
109 }
110  
111 ######################################################################
112  
113 =item run(@script)
114  
115 Sends a user-specified AppleScript to this application. The script
116 can be a simple one-liner or a multi-line script; in either case,
117 script lines should not contain newlines. If the script returns a
118 value, it will be parsed into Perl data structures.
119  
120 =cut
121  
122 sub run {
123 my ($self, @script) = @_;
124  
125 return $self->SUPER::run(
126 "tell " . $self->ref,
127 @script,
128 "end tell",
129 );
130 }
131  
132 ######################################################################
133  
134 =item objref($ref)
135  
136 =item objref($class => $string)
137  
138 Creates an object reference to use as a standalone object. If you
139 have a complete object reference (like C<application "Finder">), you
140 can pass that as a single argument:
141  
142 $app->objref('application "Finder"');
143  
144 You can also have C<objref()> make up the object reference for you out
145 of a class and string:
146  
147 $app->objref(application => 'Finder');
148  
149 This is simply a shortcut to calling Mac::AppleScript::Glue::Object's
150 C<new> method.
151  
152 =cut
153  
154 sub objref {
155 my $self = shift;
156  
157 my $ref;
158  
159 if (@_ > 1) {
160 my ($class, $string) = (shift, shift);
161 $class =~ s/_/ /g;
162 $ref = "$class \"$string\"";
163  
164 } else {
165 $ref = shift;
166 }
167  
168 return new Mac::AppleScript::Glue::Object(
169 ref => $ref,
170 app => $self,
171 );
172 }
173  
174 ######################################################################
175  
176 =back
177  
178 =head1 SEE ALSO
179  
180 L<Mac::AppleScript::Glue>
181  
182 L<Mac::AppleScript::Glue::Application>
183  
184  
185 =head1 AUTHOR
186  
187 John Labovitz E<lt>johnl@johnlabovitz.comE<gt>
188  
189  
190 =head1 COPYRIGHT
191  
192 Copyright (c) 2002 John Labovitz. All rights reserved. This program is
193 free software; you can redistribute it and/or modify it under the same
194 terms as Perl itself.
195  
196 =cut
197  
198 1;