blib/lib/App/Open/Using.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 =pod
2  
3 =head1 NAME
4  
5 App::Open::Using - Configuring and using App::Open and the `openit` commandline tool.
6  
7 =head1 BASIC USAGE
8  
9 Here's how `openit` likes to be used:
10  
11 $ openit myfile.tar.gz
12 OR
13 $ openit http://example.org
14  
15 `openit`, on successful location of a program used to open your file, runs that
16 program against your file. In the .tar.gz case, it may be an archive viewer or
17 `tar tvzf` or if you're feeling lucky, `tar vxzf`. You control how it finds
18 that program by giving it a backend that supplies launch information to the
19 `openit` program.
20  
21 You may notice some strong similarities to `openit` on Mac OS X/NeXTStep or (I am
22 told) `start` on Microsoft Windows. This application is modeled after the OS X
23 `openit` program.
24  
25 =head1 WHAT THE HELL ARE BACKENDS FOR?
26  
27 I miss `openit` from OS X. This, as stated before, is a homage to that, but
28 attempts to recognize the fact that modern UNIX systems have MIME and program
29 launching information in a million places, and that you may only care about one
30 or two of them.
31  
32 So we accomplish this by providing various backends to be leveraged that can
33 access that data. There is a separate document, App::Open::Backend, which goes
34 into the backend interface should you wish to write or modify one.
35  
36 =head1 Ok, this thing doesn't work/sucks/hasn't provided me with a config sample yet.
37  
38 If you're looking to use multiple backends, look at B<MULTIPLE
39 BACKENDS> below. If you don't like reading or just want to get
40 started, in the contrib/ directory of the distribution there are a few
41 configurations that should work with most systems.
42  
43 App::Open requires a configuration file ($HOME/.openrc) to define the backends
44 you want to use. These backends may have further requirements, which should be
45 located in their individual documentation.
46  
47 Because the author is unbelievably lazy, YAML is used for the configuration,
48 with a fixed data structure.
49  
50 A basic, one-backend configuration looks something like this:
51  
52 ----
53 backend:
54 "BackendName":
55 - "backend"
56 - "specific"
57 - "arguments"
58  
59 For example, the MailCap backend:
60  
61 ----
62 backend:
63 "MailCap":
64  
65 Or maybe you want to use a specific file (see App::Open::Backend::MailCap):
66  
67 ----
68 backend:
69 "MailCap":
70 - "/etc/my_special_mailcap"
71  
72 The structure is simple:
73  
74 =over 4
75  
76 =item Root
77  
78 Keys are names of sections, values are section configuration. Currently only
79 "backend" is supported.
80  
81 =over 4
82  
83 =item "backend" Section
84  
85 A hash, the key is the name of the backend (a full package name or just the
86 name with App::Open::Backend:: stripped), the value is an array (elements prefixed by `-`).
87  
88 =over 4
89  
90 =item backend arguments
91  
92 Backend arguments will always be an array, and are specific to the backend.
93  
94 =back
95  
96 =back
97  
98 =back
99  
100 Backends are order-dependent and the first one to return a program that matches
101 your filename or URL will be executed.
102  
103 You can use this scheme with multiple backends, but resolution order
104 cannot be guaranteed. The next section goes into setting up multiple
105 backends with a guaranteed resolution order.
106  
107 =head1 MULTIPLE BACKENDS
108  
109 An order-dependent configuration looks something like this:
110  
111 ---
112 backend:
113 - name: "YAML"
114 args:
115 - "t/resource/backends/yaml/def1.yaml"
116 - name: "MailCap"
117  
118 In this configuration, the "YAML" backend will be used first (using
119 the "def1.yaml" as the mapping), and if nothing is found, the
120 "MailCap" backend will be consulted.
121  
122 The structure lays out like this:
123  
124 =over 4
125  
126 =item Root
127  
128 Keys are names of sections, values are section configuration. Currently only
129 "backend" is supported.
130  
131 =over 4
132  
133 =item "backend" Section
134  
135 An array (items prefixed with `-') that contains a hash with two key/value
136 pairs, listed below.
137  
138 =over 4
139  
140 =item name
141  
142 The value for this key is the name of the backend, and has the same
143 naming rules as the backend name in single-backend configuration. This
144 is required.
145  
146 =item args
147  
148 Optional argument, an array of parameters to configure the backend.
149 Corresponds to the array value in single-backend configuration.
150  
151 =back
152  
153 =back
154  
155 =back
156  
157 =head1 How is my file's program located?
158  
159 URLs are trivial: a program is found for your protocol scheme. It gets launched.
160  
161 Filenames are less trivial but not complex. A filename's extensions are
162 extracted, and pieced into a list which are increasingly more diminuitive. This
163 is a non-issue for filenames which only have one extension (.gz), but is one
164 for filenames with more than one (.tar.gz).
165  
166 What will happen in the latter case is that the filename's extensions will be
167 coerced into a search path as such: ".tar.gz, .gz". These extensions will be
168 searched in order for a matching program, f.e., if you have "gunzip" for the
169 .gz extension, and .tar.gz has nothing, "gunzip" will be called. If you have a
170 .tar.gz entry of "tar tvzf", it will be called instead of gunzip, regardless if
171 the defintion exists.
172  
173 With all searches, the first program found is the one used. Leveraging multiple
174 backends may benefit you (mailcap makes no concessions for urls, f.e.), or
175 makes a seemingly innocent program a maintenance nightmare. Do what feels right.
176  
177 =head1 How is my file executed?
178  
179 The full command string is returned by the backend to the core application,
180 which then splits it into separate arguments for passing to the system() call.
181 This (in all cases I can think of) does not use a subshell and thus is fairly
182 immune to quoting issues. The exit status from the system call is what `openit`
183 uses to exit with, so your shell's $? equivalent should properly reflect the
184 status of your execution.
185  
186 In most cases, the filename is simply the last argument to system(). However,
187 this is not always reasonable or desirable, so a special format definition,
188 '%s' is used.
189  
190 Most backends do this for you, but some do not, and therefore it's important to
191 cover it here so I don't have to retype it.
192  
193 Examples:
194  
195 =over 4
196  
197 =item tar xvzf
198  
199 When launched, "tar xvzf filename" will be executed.
200  
201 =item annoyingcmd -that -overuses %s -popt
202  
203 When launched, "annoyingcmd -that -overuses filename -popt" will be executed.
204  
205 =back
206  
207 In almost all cases the first scenario will be easier on the eyes and exactly
208 what you need. In many cases you'll be using a backend that won't cause you to
209 worry about this.
210  
211 B<WARNING>: No bundled backend nor App::Open make any attempt to do your shell
212 quoting for you. While this generally isn't an issue, it's important to be
213 aware of it.
214  
215 =cut