| 1 | =pod | ||
| 2 | |||
| 3 | =head1 AUTHORING A BACKEND | ||
| 4 | |||
| 5 | Backends have a trivial API and can communicate upwards to the App::Open core | ||
| 6 | through a series of exceptions and call returns. | ||
| 7 | |||
| 8 | The rest of this document will describe the required API and exceptions you can | ||
| 9 | throw that App::Open will recognize. | ||
| 10 | |||
| 11 | =head1 REQUIRED API | ||
| 12 | |||
| 13 | =head2 Methods | ||
| 14 | |||
| 15 | =over 4 | ||
| 16 | |||
| 17 | =item new($args) | ||
| 18 | |||
| 19 | `$args` can be an array ref or undef as passed to the constructor. It will | ||
| 20 | return a blessed object that has the methods listed below in the | ||
| 21 | namespace the object is bound to. | ||
| 22 | |||
| 23 | It is ok to require arguments, but the ideal case is to require as | ||
| 24 | little configuration as possible, leaving the user to expect | ||
| 25 | reasonable defaults without arguments. | ||
| 26 | |||
| 27 | =item lookup_file($extension) | ||
| 28 | |||
| 29 | Looks up the command string for `$extension`. | ||
| 30 | |||
| 31 | The string returned should be usable in the shell as a full command, | ||
| 32 | with one potential exception, explained below. The command will then | ||
| 33 | be processed by the App::Open system and executed if possible. | ||
| 34 | |||
| 35 | `%s' in a command string allows the App::Open system to substitute the | ||
| 36 | filename in place of this format variable... f.e.: | ||
| 37 | |||
| 38 | "firefox %s -newtab" | ||
| 39 | |||
| 40 | %s will correspond to the filename/url that was the source for this | ||
| 41 | lookup after App::Open gets its hands back on it. | ||
| 42 | |||
| 43 | In the case that %s is omitted, the filename/url is appended to the | ||
| 44 | end of the command string. | ||
| 45 | |||
| 46 | App::Open actually splits up the command string for usage via | ||
| 47 | multiple-argument system() and as such shell quoting issues are rarely | ||
| 48 | an issue, but either you or the user are responsible for these issues, | ||
| 49 | App::Open will make no attempt to fix or add quoting. | ||
| 50 | |||
| 51 | =item lookup_url($scheme) | ||
| 52 | |||
| 53 | `$scheme` is a url protocol scheme, e.g., "https" or "ftp". Other than | ||
| 54 | this detail, it is expected to use the exact same semantics as | ||
| 55 | lookup_file(). | ||
| 56 | |||
| 57 | =back | ||
| 58 | |||
| 59 | =head2 Exceptions | ||
| 60 | |||
| 61 | For this document, exceptions are triggered by calling die() with a | ||
| 62 | specific argument string. Some exceptions take optional arguments, which are | ||
| 63 | delimited by spaces in the die string. | ||
| 64 | |||
| 65 | Example: | ||
| 66 | |||
| 67 | die "INVALID_CONFIGURATION"; # exception for invalid configuration | ||
| 68 | die "ANOTHER_EXCEPTION that has four arguments"; # an exception with arguments | ||
| 69 | |||
| 70 | While there's nothing stopping you from processing exceptions this way | ||
| 71 | in your own backends, these exceptions are mainly for the benefit of | ||
| 72 | the App::Open core. The core uses these exceptions to provide useful | ||
| 73 | output to the user when there's an error running the `openit` command. | ||
| 74 | |||
| 75 | Anyways, on to the list of recognized exceptions. | ||
| 76 | |||
| 77 | =over 4 | ||
| 78 | |||
| 79 | =item MISSING_ARGUMENT | ||
| 80 | |||
| 81 | =item INVALID_ARGUMENT | ||
| 82 | |||
| 83 | =item FILE_NOT_FOUND | ||
| 84 | |||
| 85 | =item INVALID_CONFIGURATION | ||
| 86 | |||
| 87 | I hope these are self-explanatory. | ||
| 88 | |||
| 89 | =item NO_PROGRAM | ||
| 90 | |||
| 91 | This is generally thrown by App::Open itself, when no matches for a | ||
| 92 | given extension/scheme are found. However, if your backend depends on | ||
| 93 | a program to perform lookups and can't find it, it would be | ||
| 94 | appropriate to throw this. | ||
| 95 | |||
| 96 | =item NO_BACKEND_FOUND backend_name | ||
| 97 | |||
| 98 | Used by App::Open::Config when initializing backends, and one cannot | ||
| 99 | be loaded. It's unlikely you will ever need this. | ||
| 100 | |||
| 101 | =item BACKEND_CONFIG_ERROR | ||
| 102 | |||
| 103 | This is what you will most often use; if you require arguments or | ||
| 104 | merely get garbage arguments, this is what you throw, and the `openit` | ||
| 105 | program will direct the user to your backend documentation. Obviously, | ||
| 106 | this can be used in less obvious cases. | ||
| 107 | |||
| 108 | =back | ||
| 109 | |||
| 110 | =head1 EXAMPLES | ||
| 111 | |||
| 112 | Please look at App::Open::Backend::Dummy for a very basic rundown of | ||
| 113 | the API. This is what's used to test the backend interface | ||
| 114 | functionality, and as such will remain updated along with this | ||
| 115 | document concerning any changes to the API. | ||
| 116 | |||
| 117 | If you'd like something with more meat, App:;Open::Backend::YAML is | ||
| 118 | fully functional and relatively simple to understand. | ||
| 119 | |||
| 120 | =head1 CONTRIBUTING BACKENDS | ||
| 121 | |||
| 122 | It is the author's desire that backends released be packaged | ||
| 123 | separately from App::Open and available via CPAN. | ||
| 124 | |||
| 125 | However, he will gladly consider backends for inclusion in this | ||
| 126 | package that: | ||
| 127 | |||
| 128 | =over 4 | ||
| 129 | |||
| 130 | =item Do not add dependencies | ||
| 131 | |||
| 132 | =item Do not make assumptions about the operating system or installed tools | ||
| 133 | |||
| 134 | =item Are fully tested and documented | ||
| 135 | |||
| 136 | =back | ||
| 137 | |||
| 138 | In other words, you're better off just releasing it yourself. | ||
| 139 | |||
| 140 | =cut |