├── .gitignore
├── LICENSE.md
├── README.md
├── bin
├── denicify.pl
├── lib
│ ├── NIC
│ │ ├── Bridge
│ │ │ ├── Context.pm
│ │ │ ├── Directory.pm
│ │ │ ├── File.pm
│ │ │ ├── NICBase.pm
│ │ │ ├── NICType.pm
│ │ │ ├── Symlink.pm
│ │ │ ├── Tie
│ │ │ │ └── WrappedMethod.pm
│ │ │ ├── _BridgedObject.pm
│ │ │ └── _Undefined.pm
│ │ ├── Formats
│ │ │ ├── NIC1.pm
│ │ │ ├── NICTar.pm
│ │ │ └── NICTar
│ │ │ │ ├── Directory.pm
│ │ │ │ ├── File.pm
│ │ │ │ ├── Symlink.pm
│ │ │ │ └── _TarMixin.pm
│ │ ├── NICBase.pm
│ │ ├── NICBase
│ │ │ ├── Directory.pm
│ │ │ ├── File.pm
│ │ │ └── Symlink.pm
│ │ ├── NICType.pm
│ │ └── Tie
│ │ │ ├── Method.pm
│ │ │ └── PrefixedHandleRedirect.pm
│ └── parent.pm
├── nic.pl
└── nicify.pl
├── package.json
└── templates
└── .keep
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | ._*
3 |
4 | templates/*
5 | !*/.keep
6 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Theos (and by extension, Logos) is available under the provisions of the GNU
2 | General Public License, version 3 (or later), available here:
3 | http://www.gnu.org/licenses/gpl-3.0.html.
4 |
5 | Projects created using Theos and/or Logos are not considered derivative works
6 | (from a licensing standpoint, or, for that matter, any other standpoint) and
7 | are, as such, not required to be licensed under the GNU GPL.
8 |
9 | The included project templates are license-free. The use of a template does
10 | not confer a license to your project.
11 |
12 | ----
13 |
14 | GNU GENERAL PUBLIC LICENSE
15 | ==========================
16 |
17 | Version 3, 29 June 2007
18 |
19 | Copyright © 2007 Free Software Foundation, Inc. <>
20 |
21 | Everyone is permitted to copy and distribute verbatim copies of this license
22 | document, but changing it is not allowed.
23 |
24 | ## Preamble
25 |
26 | The GNU General Public License is a free, copyleft license for software and other
27 | kinds of works.
28 |
29 | The licenses for most software and other practical works are designed to take away
30 | your freedom to share and change the works. By contrast, the GNU General Public
31 | License is intended to guarantee your freedom to share and change all versions of a
32 | program--to make sure it remains free software for all its users. We, the Free
33 | Software Foundation, use the GNU General Public License for most of our software; it
34 | applies also to any other work released this way by its authors. You can apply it to
35 | your programs, too.
36 |
37 | When we speak of free software, we are referring to freedom, not price. Our General
38 | Public Licenses are designed to make sure that you have the freedom to distribute
39 | copies of free software (and charge for them if you wish), that you receive source
40 | code or can get it if you want it, that you can change the software or use pieces of
41 | it in new free programs, and that you know you can do these things.
42 |
43 | To protect your rights, we need to prevent others from denying you these rights or
44 | asking you to surrender the rights. Therefore, you have certain responsibilities if
45 | you distribute copies of the software, or if you modify it: responsibilities to
46 | respect the freedom of others.
47 |
48 | For example, if you distribute copies of such a program, whether gratis or for a fee,
49 | you must pass on to the recipients the same freedoms that you received. You must make
50 | sure that they, too, receive or can get the source code. And you must show them these
51 | terms so they know their rights.
52 |
53 | Developers that use the GNU GPL protect your rights with two steps: (1) assert
54 | copyright on the software, and (2) offer you this License giving you legal permission
55 | to copy, distribute and/or modify it.
56 |
57 | For the developers' and authors' protection, the GPL clearly explains that there is
58 | no warranty for this free software. For both users' and authors' sake, the GPL
59 | requires that modified versions be marked as changed, so that their problems will not
60 | be attributed erroneously to authors of previous versions.
61 |
62 | Some devices are designed to deny users access to install or run modified versions of
63 | the software inside them, although the manufacturer can do so. This is fundamentally
64 | incompatible with the aim of protecting users' freedom to change the software. The
65 | systematic pattern of such abuse occurs in the area of products for individuals to
66 | use, which is precisely where it is most unacceptable. Therefore, we have designed
67 | this version of the GPL to prohibit the practice for those products. If such problems
68 | arise substantially in other domains, we stand ready to extend this provision to
69 | those domains in future versions of the GPL, as needed to protect the freedom of
70 | users.
71 |
72 | Finally, every program is threatened constantly by software patents. States should
73 | not allow patents to restrict development and use of software on general-purpose
74 | computers, but in those that do, we wish to avoid the special danger that patents
75 | applied to a free program could make it effectively proprietary. To prevent this, the
76 | GPL assures that patents cannot be used to render the program non-free.
77 |
78 | The precise terms and conditions for copying, distribution and modification follow.
79 |
80 | ## TERMS AND CONDITIONS
81 |
82 | ### 0. Definitions.
83 |
84 | “This License” refers to version 3 of the GNU General Public License.
85 |
86 | “Copyright” also means copyright-like laws that apply to other kinds of
87 | works, such as semiconductor masks.
88 |
89 | “The Program” refers to any copyrightable work licensed under this
90 | License. Each licensee is addressed as “you”. “Licensees” and
91 | “recipients” may be individuals or organizations.
92 |
93 | To “modify” a work means to copy from or adapt all or part of the work in
94 | a fashion requiring copyright permission, other than the making of an exact copy. The
95 | resulting work is called a “modified version” of the earlier work or a
96 | work “based on” the earlier work.
97 |
98 | A “covered work” means either the unmodified Program or a work based on
99 | the Program.
100 |
101 | To “propagate” a work means to do anything with it that, without
102 | permission, would make you directly or secondarily liable for infringement under
103 | applicable copyright law, except executing it on a computer or modifying a private
104 | copy. Propagation includes copying, distribution (with or without modification),
105 | making available to the public, and in some countries other activities as well.
106 |
107 | To “convey” a work means any kind of propagation that enables other
108 | parties to make or receive copies. Mere interaction with a user through a computer
109 | network, with no transfer of a copy, is not conveying.
110 |
111 | An interactive user interface displays “Appropriate Legal Notices” to the
112 | extent that it includes a convenient and prominently visible feature that (1)
113 | displays an appropriate copyright notice, and (2) tells the user that there is no
114 | warranty for the work (except to the extent that warranties are provided), that
115 | licensees may convey the work under this License, and how to view a copy of this
116 | License. If the interface presents a list of user commands or options, such as a
117 | menu, a prominent item in the list meets this criterion.
118 |
119 | ### 1. Source Code.
120 |
121 | The “source code” for a work means the preferred form of the work for
122 | making modifications to it. “Object code” means any non-source form of a
123 | work.
124 |
125 | A “Standard Interface” means an interface that either is an official
126 | standard defined by a recognized standards body, or, in the case of interfaces
127 | specified for a particular programming language, one that is widely used among
128 | developers working in that language.
129 |
130 | The “System Libraries” of an executable work include anything, other than
131 | the work as a whole, that (a) is included in the normal form of packaging a Major
132 | Component, but which is not part of that Major Component, and (b) serves only to
133 | enable use of the work with that Major Component, or to implement a Standard
134 | Interface for which an implementation is available to the public in source code form.
135 | A “Major Component”, in this context, means a major essential component
136 | (kernel, window system, and so on) of the specific operating system (if any) on which
137 | the executable work runs, or a compiler used to produce the work, or an object code
138 | interpreter used to run it.
139 |
140 | The “Corresponding Source” for a work in object code form means all the
141 | source code needed to generate, install, and (for an executable work) run the object
142 | code and to modify the work, including scripts to control those activities. However,
143 | it does not include the work's System Libraries, or general-purpose tools or
144 | generally available free programs which are used unmodified in performing those
145 | activities but which are not part of the work. For example, Corresponding Source
146 | includes interface definition files associated with source files for the work, and
147 | the source code for shared libraries and dynamically linked subprograms that the work
148 | is specifically designed to require, such as by intimate data communication or
149 | control flow between those subprograms and other parts of the work.
150 |
151 | The Corresponding Source need not include anything that users can regenerate
152 | automatically from other parts of the Corresponding Source.
153 |
154 | The Corresponding Source for a work in source code form is that same work.
155 |
156 | ### 2. Basic Permissions.
157 |
158 | All rights granted under this License are granted for the term of copyright on the
159 | Program, and are irrevocable provided the stated conditions are met. This License
160 | explicitly affirms your unlimited permission to run the unmodified Program. The
161 | output from running a covered work is covered by this License only if the output,
162 | given its content, constitutes a covered work. This License acknowledges your rights
163 | of fair use or other equivalent, as provided by copyright law.
164 |
165 | You may make, run and propagate covered works that you do not convey, without
166 | conditions so long as your license otherwise remains in force. You may convey covered
167 | works to others for the sole purpose of having them make modifications exclusively
168 | for you, or provide you with facilities for running those works, provided that you
169 | comply with the terms of this License in conveying all material for which you do not
170 | control copyright. Those thus making or running the covered works for you must do so
171 | exclusively on your behalf, under your direction and control, on terms that prohibit
172 | them from making any copies of your copyrighted material outside their relationship
173 | with you.
174 |
175 | Conveying under any other circumstances is permitted solely under the conditions
176 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
177 |
178 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
179 |
180 | No covered work shall be deemed part of an effective technological measure under any
181 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
182 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
183 | of such measures.
184 |
185 | When you convey a covered work, you waive any legal power to forbid circumvention of
186 | technological measures to the extent such circumvention is effected by exercising
187 | rights under this License with respect to the covered work, and you disclaim any
188 | intention to limit operation or modification of the work as a means of enforcing,
189 | against the work's users, your or third parties' legal rights to forbid circumvention
190 | of technological measures.
191 |
192 | ### 4. Conveying Verbatim Copies.
193 |
194 | You may convey verbatim copies of the Program's source code as you receive it, in any
195 | medium, provided that you conspicuously and appropriately publish on each copy an
196 | appropriate copyright notice; keep intact all notices stating that this License and
197 | any non-permissive terms added in accord with section 7 apply to the code; keep
198 | intact all notices of the absence of any warranty; and give all recipients a copy of
199 | this License along with the Program.
200 |
201 | You may charge any price or no price for each copy that you convey, and you may offer
202 | support or warranty protection for a fee.
203 |
204 | ### 5. Conveying Modified Source Versions.
205 |
206 | You may convey a work based on the Program, or the modifications to produce it from
207 | the Program, in the form of source code under the terms of section 4, provided that
208 | you also meet all of these conditions:
209 |
210 | * **a)** The work must carry prominent notices stating that you modified it, and giving a
211 | relevant date.
212 | * **b)** The work must carry prominent notices stating that it is released under this
213 | License and any conditions added under section 7. This requirement modifies the
214 | requirement in section 4 to “keep intact all notices”.
215 | * **c)** You must license the entire work, as a whole, under this License to anyone who
216 | comes into possession of a copy. This License will therefore apply, along with any
217 | applicable section 7 additional terms, to the whole of the work, and all its parts,
218 | regardless of how they are packaged. This License gives no permission to license the
219 | work in any other way, but it does not invalidate such permission if you have
220 | separately received it.
221 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal
222 | Notices; however, if the Program has interactive interfaces that do not display
223 | Appropriate Legal Notices, your work need not make them do so.
224 |
225 | A compilation of a covered work with other separate and independent works, which are
226 | not by their nature extensions of the covered work, and which are not combined with
227 | it such as to form a larger program, in or on a volume of a storage or distribution
228 | medium, is called an “aggregate” if the compilation and its resulting
229 | copyright are not used to limit the access or legal rights of the compilation's users
230 | beyond what the individual works permit. Inclusion of a covered work in an aggregate
231 | does not cause this License to apply to the other parts of the aggregate.
232 |
233 | ### 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms of sections 4 and
236 | 5, provided that you also convey the machine-readable Corresponding Source under the
237 | terms of this License, in one of these ways:
238 |
239 | * **a)** Convey the object code in, or embodied in, a physical product (including a
240 | physical distribution medium), accompanied by the Corresponding Source fixed on a
241 | durable physical medium customarily used for software interchange.
242 | * **b)** Convey the object code in, or embodied in, a physical product (including a
243 | physical distribution medium), accompanied by a written offer, valid for at least
244 | three years and valid for as long as you offer spare parts or customer support for
245 | that product model, to give anyone who possesses the object code either (1) a copy of
246 | the Corresponding Source for all the software in the product that is covered by this
247 | License, on a durable physical medium customarily used for software interchange, for
248 | a price no more than your reasonable cost of physically performing this conveying of
249 | source, or (2) access to copy the Corresponding Source from a network server at no
250 | charge.
251 | * **c)** Convey individual copies of the object code with a copy of the written offer to
252 | provide the Corresponding Source. This alternative is allowed only occasionally and
253 | noncommercially, and only if you received the object code with such an offer, in
254 | accord with subsection 6b.
255 | * **d)** Convey the object code by offering access from a designated place (gratis or for
256 | a charge), and offer equivalent access to the Corresponding Source in the same way
257 | through the same place at no further charge. You need not require recipients to copy
258 | the Corresponding Source along with the object code. If the place to copy the object
259 | code is a network server, the Corresponding Source may be on a different server
260 | (operated by you or a third party) that supports equivalent copying facilities,
261 | provided you maintain clear directions next to the object code saying where to find
262 | the Corresponding Source. Regardless of what server hosts the Corresponding Source,
263 | you remain obligated to ensure that it is available for as long as needed to satisfy
264 | these requirements.
265 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform
266 | other peers where the object code and Corresponding Source of the work are being
267 | offered to the general public at no charge under subsection 6d.
268 |
269 | A separable portion of the object code, whose source code is excluded from the
270 | Corresponding Source as a System Library, need not be included in conveying the
271 | object code work.
272 |
273 | A “User Product” is either (1) a “consumer product”, which
274 | means any tangible personal property which is normally used for personal, family, or
275 | household purposes, or (2) anything designed or sold for incorporation into a
276 | dwelling. In determining whether a product is a consumer product, doubtful cases
277 | shall be resolved in favor of coverage. For a particular product received by a
278 | particular user, “normally used” refers to a typical or common use of
279 | that class of product, regardless of the status of the particular user or of the way
280 | in which the particular user actually uses, or expects or is expected to use, the
281 | product. A product is a consumer product regardless of whether the product has
282 | substantial commercial, industrial or non-consumer uses, unless such uses represent
283 | the only significant mode of use of the product.
284 |
285 | “Installation Information” for a User Product means any methods,
286 | procedures, authorization keys, or other information required to install and execute
287 | modified versions of a covered work in that User Product from a modified version of
288 | its Corresponding Source. The information must suffice to ensure that the continued
289 | functioning of the modified object code is in no case prevented or interfered with
290 | solely because modification has been made.
291 |
292 | If you convey an object code work under this section in, or with, or specifically for
293 | use in, a User Product, and the conveying occurs as part of a transaction in which
294 | the right of possession and use of the User Product is transferred to the recipient
295 | in perpetuity or for a fixed term (regardless of how the transaction is
296 | characterized), the Corresponding Source conveyed under this section must be
297 | accompanied by the Installation Information. But this requirement does not apply if
298 | neither you nor any third party retains the ability to install modified object code
299 | on the User Product (for example, the work has been installed in ROM).
300 |
301 | The requirement to provide Installation Information does not include a requirement to
302 | continue to provide support service, warranty, or updates for a work that has been
303 | modified or installed by the recipient, or for the User Product in which it has been
304 | modified or installed. Access to a network may be denied when the modification itself
305 | materially and adversely affects the operation of the network or violates the rules
306 | and protocols for communication across the network.
307 |
308 | Corresponding Source conveyed, and Installation Information provided, in accord with
309 | this section must be in a format that is publicly documented (and with an
310 | implementation available to the public in source code form), and must require no
311 | special password or key for unpacking, reading or copying.
312 |
313 | ### 7. Additional Terms.
314 |
315 | “Additional permissions” are terms that supplement the terms of this
316 | License by making exceptions from one or more of its conditions. Additional
317 | permissions that are applicable to the entire Program shall be treated as though they
318 | were included in this License, to the extent that they are valid under applicable
319 | law. If additional permissions apply only to part of the Program, that part may be
320 | used separately under those permissions, but the entire Program remains governed by
321 | this License without regard to the additional permissions.
322 |
323 | When you convey a copy of a covered work, you may at your option remove any
324 | additional permissions from that copy, or from any part of it. (Additional
325 | permissions may be written to require their own removal in certain cases when you
326 | modify the work.) You may place additional permissions on material, added by you to a
327 | covered work, for which you have or can give appropriate copyright permission.
328 |
329 | Notwithstanding any other provision of this License, for material you add to a
330 | covered work, you may (if authorized by the copyright holders of that material)
331 | supplement the terms of this License with terms:
332 |
333 | * **a)** Disclaiming warranty or limiting liability differently from the terms of
334 | sections 15 and 16 of this License; or
335 | * **b)** Requiring preservation of specified reasonable legal notices or author
336 | attributions in that material or in the Appropriate Legal Notices displayed by works
337 | containing it; or
338 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that
339 | modified versions of such material be marked in reasonable ways as different from the
340 | original version; or
341 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the
342 | material; or
343 | * **e)** Declining to grant rights under trademark law for use of some trade names,
344 | trademarks, or service marks; or
345 | * **f)** Requiring indemnification of licensors and authors of that material by anyone
346 | who conveys the material (or modified versions of it) with contractual assumptions of
347 | liability to the recipient, for any liability that these contractual assumptions
348 | directly impose on those licensors and authors.
349 |
350 | All other non-permissive additional terms are considered “further
351 | restrictions” within the meaning of section 10. If the Program as you received
352 | it, or any part of it, contains a notice stating that it is governed by this License
353 | along with a term that is a further restriction, you may remove that term. If a
354 | license document contains a further restriction but permits relicensing or conveying
355 | under this License, you may add to a covered work material governed by the terms of
356 | that license document, provided that the further restriction does not survive such
357 | relicensing or conveying.
358 |
359 | If you add terms to a covered work in accord with this section, you must place, in
360 | the relevant source files, a statement of the additional terms that apply to those
361 | files, or a notice indicating where to find the applicable terms.
362 |
363 | Additional terms, permissive or non-permissive, may be stated in the form of a
364 | separately written license, or stated as exceptions; the above requirements apply
365 | either way.
366 |
367 | ### 8. Termination.
368 |
369 | You may not propagate or modify a covered work except as expressly provided under
370 | this License. Any attempt otherwise to propagate or modify it is void, and will
371 | automatically terminate your rights under this License (including any patent licenses
372 | granted under the third paragraph of section 11).
373 |
374 | However, if you cease all violation of this License, then your license from a
375 | particular copyright holder is reinstated (a) provisionally, unless and until the
376 | copyright holder explicitly and finally terminates your license, and (b) permanently,
377 | if the copyright holder fails to notify you of the violation by some reasonable means
378 | prior to 60 days after the cessation.
379 |
380 | Moreover, your license from a particular copyright holder is reinstated permanently
381 | if the copyright holder notifies you of the violation by some reasonable means, this
382 | is the first time you have received notice of violation of this License (for any
383 | work) from that copyright holder, and you cure the violation prior to 30 days after
384 | your receipt of the notice.
385 |
386 | Termination of your rights under this section does not terminate the licenses of
387 | parties who have received copies or rights from you under this License. If your
388 | rights have been terminated and not permanently reinstated, you do not qualify to
389 | receive new licenses for the same material under section 10.
390 |
391 | ### 9. Acceptance Not Required for Having Copies.
392 |
393 | You are not required to accept this License in order to receive or run a copy of the
394 | Program. Ancillary propagation of a covered work occurring solely as a consequence of
395 | using peer-to-peer transmission to receive a copy likewise does not require
396 | acceptance. However, nothing other than this License grants you permission to
397 | propagate or modify any covered work. These actions infringe copyright if you do not
398 | accept this License. Therefore, by modifying or propagating a covered work, you
399 | indicate your acceptance of this License to do so.
400 |
401 | ### 10. Automatic Licensing of Downstream Recipients.
402 |
403 | Each time you convey a covered work, the recipient automatically receives a license
404 | from the original licensors, to run, modify and propagate that work, subject to this
405 | License. You are not responsible for enforcing compliance by third parties with this
406 | License.
407 |
408 | An “entity transaction” is a transaction transferring control of an
409 | organization, or substantially all assets of one, or subdividing an organization, or
410 | merging organizations. If propagation of a covered work results from an entity
411 | transaction, each party to that transaction who receives a copy of the work also
412 | receives whatever licenses to the work the party's predecessor in interest had or
413 | could give under the previous paragraph, plus a right to possession of the
414 | Corresponding Source of the work from the predecessor in interest, if the predecessor
415 | has it or can get it with reasonable efforts.
416 |
417 | You may not impose any further restrictions on the exercise of the rights granted or
418 | affirmed under this License. For example, you may not impose a license fee, royalty,
419 | or other charge for exercise of rights granted under this License, and you may not
420 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
421 | that any patent claim is infringed by making, using, selling, offering for sale, or
422 | importing the Program or any portion of it.
423 |
424 | ### 11. Patents.
425 |
426 | A “contributor” is a copyright holder who authorizes use under this
427 | License of the Program or a work on which the Program is based. The work thus
428 | licensed is called the contributor's “contributor version”.
429 |
430 | A contributor's “essential patent claims” are all patent claims owned or
431 | controlled by the contributor, whether already acquired or hereafter acquired, that
432 | would be infringed by some manner, permitted by this License, of making, using, or
433 | selling its contributor version, but do not include claims that would be infringed
434 | only as a consequence of further modification of the contributor version. For
435 | purposes of this definition, “control” includes the right to grant patent
436 | sublicenses in a manner consistent with the requirements of this License.
437 |
438 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
439 | under the contributor's essential patent claims, to make, use, sell, offer for sale,
440 | import and otherwise run, modify and propagate the contents of its contributor
441 | version.
442 |
443 | In the following three paragraphs, a “patent license” is any express
444 | agreement or commitment, however denominated, not to enforce a patent (such as an
445 | express permission to practice a patent or covenant not to sue for patent
446 | infringement). To “grant” such a patent license to a party means to make
447 | such an agreement or commitment not to enforce a patent against the party.
448 |
449 | If you convey a covered work, knowingly relying on a patent license, and the
450 | Corresponding Source of the work is not available for anyone to copy, free of charge
451 | and under the terms of this License, through a publicly available network server or
452 | other readily accessible means, then you must either (1) cause the Corresponding
453 | Source to be so available, or (2) arrange to deprive yourself of the benefit of the
454 | patent license for this particular work, or (3) arrange, in a manner consistent with
455 | the requirements of this License, to extend the patent license to downstream
456 | recipients. “Knowingly relying” means you have actual knowledge that, but
457 | for the patent license, your conveying the covered work in a country, or your
458 | recipient's use of the covered work in a country, would infringe one or more
459 | identifiable patents in that country that you have reason to believe are valid.
460 |
461 | If, pursuant to or in connection with a single transaction or arrangement, you
462 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent
463 | license to some of the parties receiving the covered work authorizing them to use,
464 | propagate, modify or convey a specific copy of the covered work, then the patent
465 | license you grant is automatically extended to all recipients of the covered work and
466 | works based on it.
467 |
468 | A patent license is “discriminatory” if it does not include within the
469 | scope of its coverage, prohibits the exercise of, or is conditioned on the
470 | non-exercise of one or more of the rights that are specifically granted under this
471 | License. You may not convey a covered work if you are a party to an arrangement with
472 | a third party that is in the business of distributing software, under which you make
473 | payment to the third party based on the extent of your activity of conveying the
474 | work, and under which the third party grants, to any of the parties who would receive
475 | the covered work from you, a discriminatory patent license (a) in connection with
476 | copies of the covered work conveyed by you (or copies made from those copies), or (b)
477 | primarily for and in connection with specific products or compilations that contain
478 | the covered work, unless you entered into that arrangement, or that patent license
479 | was granted, prior to 28 March 2007.
480 |
481 | Nothing in this License shall be construed as excluding or limiting any implied
482 | license or other defenses to infringement that may otherwise be available to you
483 | under applicable patent law.
484 |
485 | ### 12. No Surrender of Others' Freedom.
486 |
487 | If conditions are imposed on you (whether by court order, agreement or otherwise)
488 | that contradict the conditions of this License, they do not excuse you from the
489 | conditions of this License. If you cannot convey a covered work so as to satisfy
490 | simultaneously your obligations under this License and any other pertinent
491 | obligations, then as a consequence you may not convey it at all. For example, if you
492 | agree to terms that obligate you to collect a royalty for further conveying from
493 | those to whom you convey the Program, the only way you could satisfy both those terms
494 | and this License would be to refrain entirely from conveying the Program.
495 |
496 | ### 13. Use with the GNU Affero General Public License.
497 |
498 | Notwithstanding any other provision of this License, you have permission to link or
499 | combine any covered work with a work licensed under version 3 of the GNU Affero
500 | General Public License into a single combined work, and to convey the resulting work.
501 | The terms of this License will continue to apply to the part which is the covered
502 | work, but the special requirements of the GNU Affero General Public License, section
503 | 13, concerning interaction through a network will apply to the combination as such.
504 |
505 | ### 14. Revised Versions of this License.
506 |
507 | The Free Software Foundation may publish revised and/or new versions of the GNU
508 | General Public License from time to time. Such new versions will be similar in spirit
509 | to the present version, but may differ in detail to address new problems or concerns.
510 |
511 | Each version is given a distinguishing version number. If the Program specifies that
512 | a certain numbered version of the GNU General Public License “or any later
513 | version” applies to it, you have the option of following the terms and
514 | conditions either of that numbered version or of any later version published by the
515 | Free Software Foundation. If the Program does not specify a version number of the GNU
516 | General Public License, you may choose any version ever published by the Free
517 | Software Foundation.
518 |
519 | If the Program specifies that a proxy can decide which future versions of the GNU
520 | General Public License can be used, that proxy's public statement of acceptance of a
521 | version permanently authorizes you to choose that version for the Program.
522 |
523 | Later license versions may give you additional or different permissions. However, no
524 | additional obligations are imposed on any author or copyright holder as a result of
525 | your choosing to follow a later version.
526 |
527 | ### 15. Disclaimer of Warranty.
528 |
529 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
530 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
531 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
532 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
533 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
534 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
535 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
536 |
537 | ### 16. Limitation of Liability.
538 |
539 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
540 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
541 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
542 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
543 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
544 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
545 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
546 | POSSIBILITY OF SUCH DAMAGES.
547 |
548 | ### 17. Interpretation of Sections 15 and 16.
549 |
550 | If the disclaimer of warranty and limitation of liability provided above cannot be
551 | given local legal effect according to their terms, reviewing courts shall apply local
552 | law that most closely approximates an absolute waiver of all civil liability in
553 | connection with the Program, unless a warranty or assumption of liability accompanies
554 | a copy of the Program in return for a fee.
555 |
556 | END OF TERMS AND CONDITIONS
557 |
558 | ## How to Apply These Terms to Your New Programs
559 |
560 | If you develop a new program, and you want it to be of the greatest possible use to
561 | the public, the best way to achieve this is to make it free software which everyone
562 | can redistribute and change under these terms.
563 |
564 | To do so, attach the following notices to the program. It is safest to attach them
565 | to the start of each source file to most effectively state the exclusion of warranty;
566 | and each file should have at least the “copyright” line and a pointer to
567 | where the full notice is found.
568 |
569 |
570 | Copyright (C)
571 |
572 | This program is free software: you can redistribute it and/or modify
573 | it under the terms of the GNU General Public License as published by
574 | the Free Software Foundation, either version 3 of the License, or
575 | (at your option) any later version.
576 |
577 | This program is distributed in the hope that it will be useful,
578 | but WITHOUT ANY WARRANTY; without even the implied warranty of
579 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
580 | GNU General Public License for more details.
581 |
582 | You should have received a copy of the GNU General Public License
583 | along with this program. If not, see .
584 |
585 | Also add information on how to contact you by electronic and paper mail.
586 |
587 | If the program does terminal interaction, make it output a short notice like this
588 | when it starts in an interactive mode:
589 |
590 | Copyright (C)
591 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
592 | This is free software, and you are welcome to redistribute it
593 | under certain conditions; type 'show c' for details.
594 |
595 | The hypothetical commands 'show w' and 'show c' should show the appropriate parts of
596 | the General Public License. Of course, your program's commands might be different;
597 | for a GUI interface, you would use an “about box”.
598 |
599 | You should also get your employer (if you work as a programmer) or school, if any, to
600 | sign a “copyright disclaimer” for the program, if necessary. For more
601 | information on this, and how to apply and follow the GNU GPL, see
602 | <>.
603 |
604 | The GNU General Public License does not permit incorporating your program into
605 | proprietary programs. If your program is a subroutine library, you may consider it
606 | more useful to permit linking proprietary applications with the library. If this is
607 | what you want to do, use the GNU Lesser General Public License instead of this
608 | License. But first, please read
609 | <>.
610 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # New Instance Creator
2 | The New Instance Creator (you can call him Nicolas!) is a tool used alongside the [Theos](https://theos.dev/docs/) build system to generate the boilerplate for a project or subproject. It can ask questions to help you fill in certain details such as the project name. NIC templates are tar archives with a certain structure that NIC can understand. NIC was once integrated in the same Git repo as Theos, but now has been decoupled from Theos to its own repo.
3 |
4 | Documentation is available on the [NIC page](https://theos.dev/docs/nic) of [theos.dev](https://theos.dev/docs/).
5 |
6 | ## License
7 | Licensed under the GNU General Public License, version 3.0, with an exception that projects created using NIC are not required to use the same license. Refer to [LICENSE.md](LICENSE.md).
8 |
--------------------------------------------------------------------------------
/bin/denicify.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | use warnings;
4 | use FindBin;
5 | use lib "$FindBin::RealBin/lib";
6 |
7 | use NIC::NICBase;
8 |
9 | use Module::Load::Conditional 'can_load';
10 |
11 | $nicfile = $ARGV[0] if($ARGV[0]);
12 | $outputdir = $ARGV[1];
13 | if(!$nicfile || !$outputdir) {
14 | exitWithError("Syntax: $0 nicfile outputdir");
15 | }
16 |
17 | ### LOAD THE NICFILE! ###
18 | open(my $nichandle, "<", $nicfile);
19 | my $line = <$nichandle>;
20 | my $nicversion = 1;
21 | if($line =~ /^nic (\w+)$/) {
22 | $nicversion = $1;
23 | } elsif($nicfile =~ /\.tar$/) {
24 | $nicversion = "Tar";
25 | }
26 | seek($nichandle, 0, 0);
27 |
28 | my $NICPackage = "NIC$nicversion";
29 | exitWithError("I don't understand NIC version $nicversion!") if(!can_load(modules => {"NIC::Formats::$NICPackage" => undef}));
30 |
31 | {
32 | no warnings 'redefine';
33 | sub NIC::NICBase::_meetsConstraints { return 1; }
34 | }
35 |
36 | my $NIC = "NIC::Formats::$NICPackage"->new($nichandle);
37 | $NIC->addConstraint("package");
38 | close($nichandle);
39 | ### YAY! ###
40 |
41 | $NIC->build($outputdir);
42 | $NIC->dumpPreamble("pre.NIC");
43 |
44 | sub exitWithError {
45 | my $error = shift;
46 | print STDERR "[error] ", $error, $/;
47 | exit 1;
48 | }
49 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/Context.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::Context;
2 | use strict;
3 | use warnings;
4 | use subs qw(warn exit);
5 | use Module::Load::Conditional qw(can_load);
6 | use NIC::Tie::PrefixedHandleRedirect;
7 | use NIC::Bridge::NICBase;
8 |
9 | our %handlers = (
10 | PROMPT => sub { },
11 | );
12 |
13 | sub import {
14 | my $package = shift;
15 | my %arg = @_;
16 | for(keys %arg) {
17 | $handlers{$_} = $arg{$_};
18 | }
19 | }
20 |
21 | our $bridge = undef;
22 | our $global_ret = undef;
23 | our $errored_out = undef;
24 |
25 | sub NIC {
26 | return $bridge;
27 | }
28 |
29 | sub warn(@) {
30 | print STDERR "[".$bridge->{FOR}->name."/warning] ",@_,$/;
31 | }
32 |
33 | sub error(@) {
34 | print STDERR "[".$bridge->{FOR}->name."/error] ",@_,$/;
35 | $errored_out = 1;
36 | die;
37 | }
38 |
39 | sub exit {
40 | $global_ret = shift;
41 | die;
42 | }
43 |
44 | sub prompt {
45 | __PACKAGE__->_prompt($bridge->{FOR}, undef, @_);
46 | }
47 |
48 | sub _prompt {
49 | my $self = shift;
50 | my $nic = shift;
51 |
52 | my $n = scalar @_;
53 | my $opts = $_[$n-1];
54 | if(ref $opts eq "HASH") {
55 | $n--;
56 | } else {
57 | $opts = {};
58 | }
59 |
60 | my $variable;
61 | $variable = shift unless $n == 1;
62 | my $promptstring = shift;
63 |
64 | $handlers{PROMPT}->($nic, $variable, $promptstring, $opts->{default});
65 | }
66 |
67 | sub _wrap {
68 | my $self = shift;
69 | my @r = map {
70 | my $wrap = $_;
71 | my $_wrapType = $wrap ? (ref $wrap) : "_Undefined";
72 | if(!$_wrapType || (ref($wrap) && $wrap->isa("NIC::Bridge::_BridgedObject"))) {
73 | return $wrap;
74 | } else {
75 | $_wrapType =~ s/.*:://;
76 | my $wrappingClass = "NIC::Bridge::$_wrapType";
77 | can_load(modules=>{$wrappingClass=>undef}, verbose=>0) or return undef;
78 | my $wrapper = $wrappingClass->new($self, $wrap);
79 | return $wrapper;
80 | }
81 | } (@_);
82 | return @r if wantarray;
83 | return (@r > 0 ? $r[0] : undef);
84 | }
85 |
86 | sub _unwrap {
87 | my $self = shift;
88 | my @r = map { (ref($_) && $_->isa("NIC::Bridge::_BridgedObject")) ? $_->{FOR} : $_; } (@_);
89 | return @r if wantarray;
90 | return (@r > 0 ? $r[0] : undef);
91 | }
92 |
93 | sub _execute {
94 | my $self = shift;
95 | my $nic = shift;
96 | my $script = shift;
97 | my $ret = 1;
98 | {
99 | local $global_ret;
100 | local $errored_out;
101 | local $bridge = NIC::Bridge::NICBase->new($self, $nic);
102 | local $SIG{__DIE__} = sub { };
103 | tie *OVERRIDE, "NIC::Tie::PrefixedHandleRedirect", *STDERR, $nic->name;
104 | my $stdout = select(*OVERRIDE);
105 | eval("#line 1 ".$nic->name."/control.pl\n".$script);
106 | select($stdout);
107 | if(defined $errored_out) {
108 | $ret = 0;
109 | } elsif(defined $global_ret) {
110 | $ret = $global_ret;
111 | print STDERR "[".$nic->name."/error] Control script exited with status $ret.",$/;
112 | } elsif($@) {
113 | $ret = 0;
114 | print STDERR "[".$nic->name."/error] Control script exited due to an error: $@";
115 | }
116 | }
117 | return $ret;
118 | }
119 |
120 | 1;
121 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/Directory.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::Directory;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::Bridge::NICType);
5 |
6 | 1;
7 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/File.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::File;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::Bridge::NICType);
5 | use NIC::Tie::Method;
6 |
7 | sub data :lvalue {
8 | my $self = shift;
9 | tie my $tied, 'NIC::Tie::Method', $self->{FOR}, "data";
10 | $tied;
11 | }
12 |
13 | 1;
14 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/NICBase.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::NICBase;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::Bridge::_BridgedObject);
5 | use NIC::NICBase::Directory;
6 | use NIC::NICBase::File;
7 | use NIC::NICBase::Symlink;
8 |
9 | sub variables {
10 | my $self = shift;
11 | return keys %{$self->{FOR}->{VARIABLES}};
12 | }
13 |
14 | sub variable :lvalue {
15 | my $self = shift;
16 | $self->{FOR}->variable(@_);
17 | }
18 |
19 | sub mkdir {
20 | my $self = shift;
21 | my $dirname = shift;
22 | my $mode = shift;
23 | my $ref = $self->{FOR}->_getContent($dirname);
24 | NIC::NICBase::Directory->take($ref);
25 | $ref->mode($mode) if $mode;
26 | return $self->{CONTEXT}->_wrap($ref);
27 | }
28 |
29 | sub mkfile {
30 | my $self = shift;
31 | my $name = shift;
32 | my $mode = shift;
33 | my $ref = $self->{FOR}->_getContent($name);
34 | NIC::NICBase::File->take($ref);
35 | $ref->mode($mode) if $mode;
36 | return $self->{CONTEXT}->_wrap($ref);
37 | }
38 |
39 | sub symlink {
40 | my $self = shift;
41 | my $oldfile = shift;
42 | my $newfile = shift;
43 | my $ref = $self->{FOR}->_getContent($newfile);
44 |
45 | my $realtarget = ref($oldfile) ? $self->{CONTEXT}->_unwrap($oldfile) : $self->{FOR}->_getContentWithoutCreate($oldfile);
46 | $realtarget = $oldfile if !$realtarget;
47 |
48 | NIC::NICBase::Symlink->take($ref, $realtarget);
49 |
50 | return $self->{CONTEXT}->_wrap($ref);
51 | }
52 |
53 | sub lookup {
54 | my $self = shift;
55 | my $name = shift;
56 | return $self->{CONTEXT}->_wrap($self->{FOR}->_getContentWithoutCreate($name));
57 | }
58 |
59 | sub setConstraint {
60 | my $self = shift;
61 | my $constraint = shift;
62 | $self->{FOR}->addConstraint($constraint);
63 | }
64 |
65 | sub clearConstraint {
66 | my $self = shift;
67 | my $constraint = shift;
68 | $self->{FOR}->removeConstraint($constraint);
69 | }
70 |
71 | sub prompt {
72 | my $self = shift;
73 | $self->{CONTEXT}->_prompt($self->{FOR}, @_);
74 | }
75 |
76 | 1;
77 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/NICType.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::NICType;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::Bridge::_BridgedObject);
5 | use NIC::Tie::Method;
6 |
7 | sub name :lvalue {
8 | my $self = shift;
9 | tie my $tied, 'NIC::Tie::Method', $self->{FOR}, "name";
10 | $tied;
11 | }
12 |
13 | sub mode :lvalue {
14 | my $self = shift;
15 | tie my $tied, 'NIC::Tie::Method', $self->{FOR}, "mode";
16 | $tied;
17 | }
18 |
19 | sub constraints {
20 | my $self = shift;
21 | return $self->{FOR}->constraints;
22 | }
23 |
24 | sub constrain {
25 | my $self = shift;
26 | $self->{FOR}->addConstraint(shift);
27 | }
28 |
29 | 1;
30 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/Symlink.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::Symlink;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::Bridge::NICType);
5 | use NIC::Bridge::Tie::WrappedMethod;
6 |
7 | sub target :lvalue {
8 | my $self = shift;
9 | tie my $tied, 'NIC::Bridge::Tie::WrappedMethod', $self->{CONTEXT}, $self->{FOR}, "target";
10 | $tied;
11 | }
12 |
13 | 1;
14 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/Tie/WrappedMethod.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::Tie::WrappedMethod;
2 | use strict;
3 | use warnings;
4 | use parent qw(Tie::Scalar);
5 |
6 | sub TIESCALAR {
7 | my $class = shift;
8 | my $self = { CONTEXT => shift, FOR => shift, METHOD => shift };
9 | bless($self, $class);
10 | return $self;
11 | }
12 |
13 | sub FETCH {
14 | my $self = shift;
15 | my $obj = $self->{FOR};
16 | my $ret = $self->{FOR}->can($self->{METHOD})->($self->{FOR});
17 | return $self->{CONTEXT}->_wrap($ret);
18 | }
19 |
20 | sub STORE {
21 | my $self = shift;
22 | my $obj = $self->{FOR};
23 | my $in = shift;
24 | $self->{FOR}->can($self->{METHOD})->($self->{FOR}, $self->{CONTEXT}->_unwrap($in));
25 | }
26 |
27 | 1;
28 |
29 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/_BridgedObject.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::_BridgedObject;
2 | use strict;
3 | use warnings;
4 |
5 | use overload '""' => sub {
6 | my $self = shift;
7 | return "[".($self->{FOR}//"(undefined)")."]";
8 | };
9 |
10 | sub new {
11 | my $proto = shift;
12 | my $class = ref($proto) || $proto;
13 | my $self = { CONTEXT => shift, FOR => shift };
14 | bless($self, $proto);
15 | return $self;
16 | }
17 |
18 |
19 | 1;
20 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Bridge/_Undefined.pm:
--------------------------------------------------------------------------------
1 | package NIC::Bridge::_Undefined;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::Bridge::_BridgedObject);
5 |
6 | use overload "bool" => sub {
7 | return 0;
8 | };
9 |
10 | our $AUTOLOAD;
11 | sub AUTOLOAD {
12 | my $method = $AUTOLOAD;
13 | $method =~ s/.*:://;
14 | NIC::Bridge::Context::error("Method '$method' called on nonexistent NIC Bridge object.");
15 | }
16 |
17 | sub DESTROY {
18 | my $self = shift;
19 | }
20 |
21 | 1;
22 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Formats/NIC1.pm:
--------------------------------------------------------------------------------
1 | package NIC::Formats::NIC1;
2 | use parent NIC::NICBase;
3 | use strict;
4 |
5 | sub new {
6 | my $proto = shift;
7 | my $class = ref($proto) || $proto;
8 |
9 | my $fh = shift;
10 | my $self = NIC::NICBase->new(@_);
11 | bless($self, $class);
12 |
13 | $self->load($fh);
14 | return $self;
15 | }
16 |
17 | sub _processLine {
18 | my $self = shift;
19 | my $fh = shift;
20 | local $_ = shift;
21 | if(/^name \"(.*)\"$/) {
22 | $self->name($1);
23 | } elsif(/^dir (.+)$/) {
24 | $self->registerDirectory($1);
25 | } elsif(/^file (\d+) (.+)$/) {
26 | my $lines = $1;
27 | my $filename = $2;
28 | my $fref = $self->registerFile($filename);
29 | my $filedata = "";
30 | while($lines > 0) {
31 | $filedata .= <$fh>;
32 | $lines--;
33 | }
34 | $fref->data($filedata);
35 | } elsif(/^prompt (\w+) \"(.*?)\"( \"(.*?)\")?$/) {
36 | my $key = $1;
37 | my $prompt = $2;
38 | my $default = $4 || undef;
39 | $self->registerPrompt($key, $prompt, $default);
40 | } elsif(/^symlink \"(.+)\" \"(.+)\"$/) {
41 | my $name = $1;
42 | my $dest = $2;
43 | $self->registerSymlink($name, $dest);
44 | } elsif(/^constrain file \"(.+)\" to (.+)$/) {
45 | my $constraint = $2;
46 | my $filename = $1;
47 | $self->registerFileConstraint($filename, $constraint);
48 | }
49 | }
50 |
51 | sub load {
52 | my $self = shift;
53 | my $fh = shift;
54 | while(<$fh>) {
55 | $self->_processLine($fh, $_);
56 | }
57 | $self->resolveSymlinks;
58 | }
59 |
60 | 1;
61 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Formats/NICTar.pm:
--------------------------------------------------------------------------------
1 | package NIC::Formats::NICTar;
2 | use parent NIC::NICBase;
3 | use strict;
4 | use NIC::Formats::NICTar::File;
5 | use NIC::Formats::NICTar::Directory;
6 | use NIC::Formats::NICTar::Symlink;
7 | use Archive::Tar;
8 | use File::Temp;
9 | use File::Path;
10 | use File::Spec;
11 | use NIC::Bridge::Context;
12 | $Archive::Tar::WARN = 0;
13 |
14 | sub new {
15 | my $proto = shift;
16 | my $fh_or_tar = shift;
17 | my $class = ref($proto) || $proto;
18 |
19 | my $tar = ref($fh_or_tar) eq "Archive::Tar" ? $fh_or_tar : Archive::Tar->new($fh_or_tar);
20 | return undef if(!$tar);
21 |
22 | my $control = _fileFromTar(undef, $tar, "NIC/control");
23 | return undef if(!$control);
24 |
25 | my $self = NIC::NICBase->new(@_);
26 | $self->{_TAR} = $tar;
27 | bless($self, $class);
28 |
29 | $self->_processData($control->get_content);
30 | $self->load();
31 |
32 | return $self;
33 | }
34 |
35 | sub _fileClass { "NIC::Formats::NICTar::File"; }
36 | sub _directoryClass { "NIC::Formats::NICTar::Directory"; }
37 | sub _symlinkClass { "NIC::Formats::NICTar::Symlink"; }
38 |
39 | sub _fileFromTar {
40 | my $self = shift;
41 | my $tar = $self ? $self->{_TAR} : shift;
42 | my $filename = shift;
43 | my @_tarfiles = $tar->get_files("./$filename", $filename);
44 | return (scalar @_tarfiles > 0) ? $_tarfiles[0] : undef;
45 | }
46 |
47 | sub _processData {
48 | my $self = shift;
49 | my $data = shift;
50 | for(split /\n\r?/, $data) {
51 | $self->_processLine($_);
52 | }
53 | }
54 |
55 | sub _processLine {
56 | my $self = shift;
57 | local $_ = shift;
58 | if(/^name\s+\"(.*)\"$/ || /^name\s+(.*)$/) {
59 | $self->name($1);
60 | } elsif(/^prompt (\w+) \"(.*?)\"( \"(.*?)\")?$/) {
61 | my $key = $1;
62 | my $prompt = $2;
63 | my $default = $4 || undef;
64 | $self->registerPrompt($key, $prompt, $default);
65 | } elsif(/^constrain (file )?\"(.+)\" to (.+)$/) {
66 | my $constraint = $3;
67 | my $filename = $2;
68 | $self->registerFileConstraint($filename, $constraint);
69 | } elsif(/^ignore (\w+)$/) {
70 | $self->ignoreVariable($1);
71 | }
72 | }
73 |
74 | sub load {
75 | my $self = shift;
76 | for($self->{_TAR}->get_files()) {
77 | next if !$_->full_path || $_->full_path =~ /^(\.\/)?NIC(\/|$)/;
78 | my $n = $_->full_path;
79 | $n =~ s/^\.\///;
80 | next if length $n == 0;
81 | if($_->is_dir) {
82 | my $ref = $self->registerDirectory($n);
83 | $ref->tarfile($_);
84 | } elsif($_->is_symlink) {
85 | my $target = $_->linkname;
86 | $target =~ s/^\.\///;
87 |
88 | my $ref = $self->registerSymlink($n, $target);
89 | $ref->tarfile($_);
90 | } elsif($_->is_file) {
91 | my $ref = $self->registerFile($n);
92 | $ref->tarfile($_);
93 | }
94 | }
95 | $self->resolveSymlinks;
96 | }
97 |
98 | sub _execPackageScript {
99 | my $self = shift;
100 | my $script = shift;
101 | my $tarfile = $self->_fileFromTar("NIC/$script");
102 | return if !$tarfile || $tarfile->mode & 0500 != 0500;
103 | my $filename = File::Spec->catfile($self->{_TEMPDIR}, $script);
104 | my $nicfile = NIC::NICType->new($self, $filename);
105 | $self->_fileClass->take($nicfile);
106 | $nicfile->tarfile($tarfile);
107 | $nicfile->create();
108 | my $ret = system $filename $script;
109 | return ($ret >> 8) == 0
110 | }
111 |
112 | sub prebuild {
113 | my $self = shift;
114 | return $self->_execPackageScript("prebuild");
115 | }
116 |
117 | sub postbuild {
118 | my $self = shift;
119 | return $self->_execPackageScript("postbuild");
120 | }
121 |
122 | sub exec {
123 | my $self = shift;
124 | my $_controlpl = $self->_fileFromTar("NIC/control.pl");
125 | if($_controlpl) {
126 | return NIC::Bridge::Context->_execute($self, $_controlpl->get_content);
127 | }
128 | return 1;
129 | }
130 |
131 | sub build {
132 | my $self = shift;
133 |
134 | for(keys %{$self->{VARIABLES}}) {
135 | $ENV{"NIC_".$_} = $self->variable($_);
136 | }
137 |
138 | $self->{_TEMPDIR} = File::Temp::tempdir();
139 |
140 | $self->SUPER::build(@_);
141 |
142 | File::Path::rmtree($self->{_TEMPDIR});
143 | $self->{_TEMPDIR} = undef;
144 | }
145 |
146 | 1;
147 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Formats/NICTar/Directory.pm:
--------------------------------------------------------------------------------
1 | package NIC::Formats::NICTar::Directory;
2 | use parent qw(NIC::Formats::NICTar::_TarMixin NIC::NICBase::Directory);
3 | use strict;
4 |
5 | sub _take_init {
6 | my $self = shift;
7 | $self->NIC::NICBase::Directory::_take_init(@_);
8 | $self->NIC::Formats::NICTar::_TarMixin::_take_init(@_);
9 | }
10 |
11 | 1;
12 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Formats/NICTar/File.pm:
--------------------------------------------------------------------------------
1 | package NIC::Formats::NICTar::File;
2 | use parent qw(NIC::Formats::NICTar::_TarMixin NIC::NICBase::File);
3 | use strict;
4 |
5 | sub _take_init {
6 | my $self = shift;
7 | $self->NIC::NICBase::File::_take_init(@_);
8 | $self->NIC::Formats::NICTar::_TarMixin::_take_init(@_);
9 | }
10 |
11 | sub data {
12 | my $self = shift;
13 | return $self->SUPER::data(@_) // $self->tarfile->get_content;
14 | }
15 |
16 | 1;
17 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Formats/NICTar/Symlink.pm:
--------------------------------------------------------------------------------
1 | package NIC::Formats::NICTar::Symlink;
2 | use parent NIC::NICBase::Symlink;
3 | use strict;
4 |
5 | sub tarfile {
6 | my $self = shift;
7 | if(@_) { $self->{TARFILE} = shift; }
8 | return $self->{TARFILE};
9 | }
10 |
11 | 1;
12 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Formats/NICTar/_TarMixin.pm:
--------------------------------------------------------------------------------
1 | package NIC::Formats::NICTar::_TarMixin;
2 | use strict;
3 |
4 | sub _take_init {
5 | my $self = shift;
6 | $self->{TARFILE} = undef;
7 | }
8 |
9 | sub tarfile {
10 | my $self = shift;
11 | if(@_) { $self->{TARFILE} = shift; }
12 | return $self->{TARFILE};
13 | }
14 |
15 | sub _mode {
16 | my $self = shift;
17 | return $self->tarfile->mode;
18 | }
19 |
20 | 1;
21 |
--------------------------------------------------------------------------------
/bin/lib/NIC/NICBase.pm:
--------------------------------------------------------------------------------
1 | package NIC::NICBase;
2 | use strict;
3 | use warnings;
4 |
5 | use NIC::NICBase::File;
6 | use NIC::NICBase::Directory;
7 | use NIC::NICBase::Symlink;
8 |
9 | use List::Util qw(first);
10 |
11 | sub new {
12 | my $proto = shift;
13 | my $class = ref($proto) || $proto;
14 | my $self = {};
15 | $self->{NAME} = shift;
16 | $self->{CONTENTS} = [];
17 | $self->{VARIABLES} = {};
18 | $self->{CONSTRAINTS} = {};
19 | $self->{PROMPTS} = [];
20 | $self->{IGNORED_VARS} = {};
21 | bless($self, $class);
22 |
23 | return $self;
24 | }
25 |
26 | sub _fileClass { "NIC::NICBase::File"; }
27 | sub _directoryClass { "NIC::NICBase::Directory"; }
28 | sub _symlinkClass { "NIC::NICBase::Symlink"; }
29 |
30 | sub _getContentWithoutCreate {
31 | my $self = shift;
32 | my $name = shift;
33 | return first { $_->name eq $name } @{$self->{CONTENTS}};
34 | }
35 |
36 | sub _getContent {
37 | my $self = shift;
38 | my $ref = $self->_getContentWithoutCreate(@_);
39 | return $ref if $ref;
40 | $ref = NIC::NICType->new($self, @_);
41 | push(@{$self->{CONTENTS}}, $ref);
42 | return $ref;
43 | }
44 |
45 | sub _generate {
46 | my $self = shift;
47 | my $class = shift;
48 | my $name = shift;
49 | my $ref = $self->_getContent($name, @_);
50 | if($ref->type == NIC::NICType::TYPE_UNKNOWN) {
51 | $class->take($ref, @_);
52 | }
53 | return $ref;
54 | }
55 |
56 | sub registerDirectory {
57 | my $self = shift;
58 | my $dir = $self->_generate($self->_directoryClass, @_);
59 | return $dir;
60 | }
61 |
62 | sub registerFile {
63 | my $self = shift;
64 | my $file = $self->_generate($self->_fileClass, @_);
65 | return $file;
66 | }
67 |
68 | sub registerSymlink {
69 | my $self = shift;
70 | my $symlink = $self->_generate($self->_symlinkClass, @_);
71 | return $symlink;
72 | }
73 |
74 | sub registerPrompt {
75 | my($self, $key, $prompt, $default) = @_;
76 | push(@{$self->{PROMPTS}}, {
77 | name => $key,
78 | prompt => $prompt,
79 | default => $default
80 | });
81 | }
82 |
83 | sub registerFileConstraint {
84 | my $self = shift;
85 | my $filename = shift;
86 | my $constraint = shift;
87 | $self->_getContent($filename)->addConstraint($constraint);
88 | }
89 |
90 | sub resolveSymlinks {
91 | my $self = shift;
92 | for(@{$self->{CONTENTS}}) {
93 | next unless $_->type == NIC::NICType::TYPE_SYMLINK;
94 | next if $_->target_type != NIC::NICType::TYPE_UNKNOWN;
95 | my $ref = $self->_getContentWithoutCreate($_->target);
96 | $_->target($ref) if $ref;
97 | }
98 | }
99 |
100 | sub variable: lvalue {
101 | my $self = shift;
102 | my $key = shift;
103 | $self->{VARIABLES}->{$key};
104 | }
105 |
106 | sub name {
107 | my $self = shift;
108 | if(@_) { $self->{NAME} = shift; }
109 | return $self->{NAME} // "(unnamed template)";
110 | }
111 |
112 | sub prompts {
113 | my $self = shift;
114 | return @{$self->{PROMPTS}};
115 | }
116 |
117 | sub addConstraint {
118 | my $self = shift;
119 | my $constraint = shift;
120 | $self->{CONSTRAINTS}->{$constraint} = 1;
121 | }
122 |
123 | sub removeConstraint {
124 | my $self = shift;
125 | my $constraint = shift;
126 | delete $self->{CONSTRAINTS}->{$constraint};
127 | }
128 |
129 | sub _constraintMatch {
130 | my $self = shift;
131 | my $constraint = shift;
132 | my $negated = 0;
133 | if(substr($constraint, 0, 1) eq "!") {
134 | $negated = 1;
135 | substr($constraint, 0, 1, "");
136 | }
137 | return 0 if(!$negated && (!defined $self->{CONSTRAINTS}->{$constraint} || $self->{CONSTRAINTS}->{$constraint} != 1));
138 | return 0 if($negated && (defined $self->{CONSTRAINTS}->{$constraint} || $self->{CONSTRAINTS}->{$constraint} != 0));
139 | return 1;
140 | }
141 |
142 | sub _meetsConstraints {
143 | my $self = shift;
144 | my $content = shift;
145 | foreach ($content->constraints) {
146 | return 0 if !$self->_constraintMatch($_);
147 | }
148 | return 1;
149 | }
150 |
151 | sub substituteVariables {
152 | my $self = shift;
153 | my $line = shift;
154 | foreach my $key (keys %{$self->{VARIABLES}}) {
155 | my $value = $self->{VARIABLES}->{$key};
156 | $line =~ s/\@\@$key\@\@/$value/g;
157 | }
158 | return $line;
159 | }
160 |
161 | sub ignoreVariable {
162 | my $self = shift;
163 | my $var = shift;
164 | $self->{IGNORED_VARS}->{$var}++;
165 | }
166 |
167 | sub variableIgnored {
168 | my $self = shift;
169 | my $var = shift;
170 | return defined $self->{IGNORED_VARS}->{$var};
171 | }
172 |
173 | sub prebuild {
174 |
175 | }
176 |
177 | sub postbuild {
178 |
179 | }
180 |
181 | sub exec {
182 | return 1;
183 | }
184 |
185 | sub build {
186 | my $self = shift;
187 | my $dir = shift;
188 | mkdir($dir) or die "Failed to create the directory '$dir': $!\n";
189 | chdir($dir) or die $!;
190 | $self->prebuild();
191 | foreach my $content (sort { $a->type <=> $b->type } (@{$self->{CONTENTS}})) {
192 | next if $content->type == NIC::NICType::TYPE_UNKNOWN;
193 | next if !$self->_meetsConstraints($content);
194 | $content->create();
195 | }
196 | $self->postbuild();
197 | }
198 |
199 | sub dumpPreamble {
200 | my $self = shift;
201 | my $preamblefn = shift;
202 | open(my $pfh, ">", $preamblefn);
203 | print $pfh "name \"".$self->{NAME}."\"",$/;
204 | foreach my $prompt (@{$self->{PROMPTS}}) {
205 | print $pfh "prompt ".$prompt->{name}." \"".$prompt->{prompt}."\"";
206 | print $pfh " \"".$prompt->{default}."\"" if defined $prompt->{default};
207 | print $pfh $/;
208 | }
209 | foreach my $filename (keys %{$self->{FILES}}) {
210 | my $file = $self->{FILES}->{$filename};
211 | if(!defined $file->{constraints}) {
212 | next;
213 | }
214 | foreach (@{$file->{constraints}}) {
215 | print $pfh "constrain file \"".$filename."\" to ".$_,$/
216 | }
217 | }
218 | close($pfh);
219 | }
220 |
221 | 1;
222 |
--------------------------------------------------------------------------------
/bin/lib/NIC/NICBase/Directory.pm:
--------------------------------------------------------------------------------
1 | package NIC::NICBase::Directory;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::NICType);
5 | use File::Path qw(mkpath);
6 |
7 | sub type {
8 | my $self = shift;
9 | return NIC::NICType::TYPE_DIRECTORY;
10 | }
11 |
12 | sub _mode {
13 | return 0755;
14 | }
15 |
16 | sub create {
17 | my $self = shift;
18 | mkpath($self->{OWNER}->substituteVariables($self->{NAME}), { mode => $self->mode }) or return 0;
19 | return 1;
20 | }
21 |
22 |
23 | 1;
24 |
25 |
--------------------------------------------------------------------------------
/bin/lib/NIC/NICBase/File.pm:
--------------------------------------------------------------------------------
1 | package NIC::NICBase::File;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::NICType);
5 |
6 | sub _take_init {
7 | my $self = shift;
8 | $self->{DATA} = undef;
9 | }
10 |
11 | sub type {
12 | my $self = shift;
13 | return NIC::NICType::TYPE_FILE;
14 | }
15 |
16 | sub _mode {
17 | return 0644;
18 | }
19 |
20 | sub data {
21 | my $self = shift;
22 | $self->{DATA} = shift if @_;
23 | $self->{DATA};
24 | }
25 |
26 | sub create {
27 | my $self = shift;
28 | my $filename = $self->{OWNER}->substituteVariables($self->name);
29 | open(my $nicfile, ">", $filename) or return 0;
30 | print $nicfile $self->{OWNER}->substituteVariables($self->data);
31 | close($nicfile);
32 | chmod($self->mode, $filename);
33 | return 1;
34 | }
35 |
36 | 1;
37 |
--------------------------------------------------------------------------------
/bin/lib/NIC/NICBase/Symlink.pm:
--------------------------------------------------------------------------------
1 | package NIC::NICBase::Symlink;
2 | use strict;
3 | use warnings;
4 | use parent qw(NIC::NICType);
5 | use Scalar::Util qw(refaddr);
6 |
7 | use overload '""' => sub {
8 | my $self = shift;
9 | my $ref = ref($self);
10 | $ref =~ s/^.*::(\w+)$/$1/g;
11 | my $target = (ref($self->target) && refaddr($self) == refaddr($self->target)) ? "itself" : "\"".$self->target."\"";
12 | return '"'.$self->name."\" ($ref to $target)";
13 | };
14 |
15 | sub _take_init {
16 | my $self = shift;
17 | $self->{TARGET} = shift // undef;
18 | }
19 |
20 | sub type {
21 | my $self = shift;
22 | return NIC::NICType::TYPE_SYMLINK;
23 | }
24 |
25 | sub target {
26 | my $self = shift;
27 | if(@_) { $self->{TARGET} = shift; }
28 | return $self->{TARGET};
29 | }
30 |
31 | sub target_type {
32 | my $self = shift;
33 | my $t = $self->{TARGET};
34 | return ref($t) ? $t->type : NIC::NICType::TYPE_UNKNOWN;
35 | }
36 |
37 | sub target_name {
38 | my $self = shift;
39 | my $t = $self->{TARGET};
40 | return ref($t) ? $t->name : $t;
41 | }
42 |
43 | sub create {
44 | my $self = shift;
45 | my $name = $self->{OWNER}->substituteVariables($self->{NAME});
46 | my $dest = $self->{OWNER}->substituteVariables($self->target_name);
47 | symlink($dest, $name) or return 0;
48 | return 1;
49 | }
50 |
51 | 1;
52 |
53 |
--------------------------------------------------------------------------------
/bin/lib/NIC/NICType.pm:
--------------------------------------------------------------------------------
1 | package NIC::NICType;
2 | use strict;
3 | use warnings;
4 |
5 | use constant {
6 | TYPE_UNKNOWN => 0,
7 | TYPE_DIRECTORY => 1,
8 | TYPE_FILE => 2,
9 | TYPE_SYMLINK => 3
10 | };
11 |
12 | use overload '""' => sub {
13 | my $self = shift;
14 | my $ref = ref($self);
15 | $ref =~ s/^.*::(\w+)$/$1/g;
16 | return '"'.$self->name."\" ($ref, mode ".sprintf("%4.04o", $self->mode).")";
17 | };
18 |
19 | sub new {
20 | my $proto = shift;
21 | my $class = ref($proto) || $proto;
22 | my $self = {};
23 | $self->{OWNER} = shift // undef;
24 | $self->{NAME} = shift // undef;
25 | $self->{MODE} = undef;
26 | $self->{CONSTRAINTS} = [];
27 | bless($self, $class);
28 |
29 | return $self;
30 | }
31 |
32 | sub _take_init {
33 | }
34 |
35 | sub take {
36 | my $proto = shift;
37 | my $class = ref($proto) || $proto;
38 | my $obj = shift;
39 | bless($obj, $class);
40 | $obj->_take_init(@_);
41 | }
42 |
43 | sub name {
44 | my $self = shift;
45 | if(@_) { $self->{NAME} = shift; }
46 | return $self->{NAME};
47 | }
48 |
49 | sub _mode {
50 | return 0;
51 | }
52 |
53 | sub mode {
54 | my $self = shift;
55 | if(@_) { $self->{MODE} = shift; }
56 | return $self->{MODE} // $self->_mode;
57 | }
58 |
59 | sub type {
60 | my $self = shift;
61 | return TYPE_UNKNOWN;
62 | }
63 |
64 | sub constraints {
65 | my $self = shift;
66 | return @{$self->{CONSTRAINTS}};
67 | }
68 |
69 | sub addConstraint {
70 | my $self = shift;
71 | my $constraint = shift;
72 | push(@{$self->{CONSTRAINTS}}, $constraint);
73 | }
74 |
75 | sub create {
76 | return 0;
77 | }
78 |
79 | 1;
80 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Tie/Method.pm:
--------------------------------------------------------------------------------
1 | package NIC::Tie::Method;
2 | use parent qw(Tie::Scalar);
3 |
4 | sub TIESCALAR {
5 | my $class = shift;
6 | my $for = shift;
7 | my $method = shift;
8 | my $self = { FOR => $for, METHOD => $method };
9 | bless($self, $class);
10 | return $self;
11 | }
12 |
13 | sub FETCH {
14 | my $self = shift;
15 | my $obj = $self->{FOR};
16 | { unshift @_, $obj; goto &{$self->{FOR}->can($self->{METHOD})}; }
17 | }
18 |
19 | sub STORE {
20 | my $self = shift;
21 | my $obj = $self->{FOR};
22 | { unshift @_, $obj; goto &{$self->{FOR}->can($self->{METHOD})}; }
23 | }
24 |
25 | 1;
26 |
27 |
--------------------------------------------------------------------------------
/bin/lib/NIC/Tie/PrefixedHandleRedirect.pm:
--------------------------------------------------------------------------------
1 | package NIC::Tie::PrefixedHandleRedirect;
2 | use strict;
3 | use parent qw(Tie::Handle);
4 | sub TIEHANDLE {
5 | my $proto = shift;
6 | my $fh = shift;
7 | my $prefix = shift;
8 | return bless [$fh, $prefix], $proto;
9 | }
10 |
11 | sub _token {
12 | return "[".$_[0]->[1]."] ";
13 | }
14 |
15 | sub PRINT {
16 | my $t = $_[0]->_token;
17 | my $fh = $_[0]->[0];
18 | shift;
19 | my $str = $t.join('', @_);
20 | $str =~ s#$/+$##g;
21 | $str =~ s#$/#$/$t#g;
22 | print $fh $str,$/;
23 | }
24 |
25 | sub PRINTF {
26 | my $t = $_[0]->_token;
27 | my $fh = $_[0]->[0];
28 | shift;
29 | my $str = $t.sprintf(shift, @_);
30 | $str =~ s#$/+$##g;
31 | $str =~ s#$/#$/$t#g;
32 | print $fh $str,$/;
33 | }
34 | 1;
35 |
--------------------------------------------------------------------------------
/bin/lib/parent.pm:
--------------------------------------------------------------------------------
1 | package parent;
2 | use strict;
3 | use vars qw($VERSION);
4 | $VERSION = '0.234';
5 |
6 | sub import {
7 | my $class = shift;
8 |
9 | my $inheritor = caller(0);
10 |
11 | if ( @_ and $_[0] eq '-norequire' ) {
12 | shift @_;
13 | } else {
14 | for ( my @filename = @_ ) {
15 | s{::|'}{/}g;
16 | require "$_.pm"; # dies if the file is not found
17 | }
18 | }
19 |
20 | {
21 | no strict 'refs';
22 | push @{"$inheritor\::ISA"}, @_;
23 | };
24 | };
25 |
26 | "All your base are belong to us"
27 |
28 | __END__
29 |
30 | =encoding utf8
31 |
32 | =head1 NAME
33 |
34 | parent - Establish an ISA relationship with base classes at compile time
35 |
36 | =head1 SYNOPSIS
37 |
38 | package Baz;
39 | use parent qw(Foo Bar);
40 |
41 | =head1 DESCRIPTION
42 |
43 | Allows you to both load one or more modules, while setting up inheritance from
44 | those modules at the same time. Mostly similar in effect to
45 |
46 | package Baz;
47 | BEGIN {
48 | require Foo;
49 | require Bar;
50 | push @ISA, qw(Foo Bar);
51 | }
52 |
53 | By default, every base class needs to live in a file of its own.
54 | If you want to have a subclass and its parent class in the same file, you
55 | can tell C not to load any modules by using the C<-norequire> switch:
56 |
57 | package Foo;
58 | sub exclaim { "I CAN HAS PERL" }
59 |
60 | package DoesNotLoadFooBar;
61 | use parent -norequire, 'Foo', 'Bar';
62 | # will not go looking for Foo.pm or Bar.pm
63 |
64 | This is equivalent to the following code:
65 |
66 | package Foo;
67 | sub exclaim { "I CAN HAS PERL" }
68 |
69 | package DoesNotLoadFooBar;
70 | push @DoesNotLoadFooBar::ISA, 'Foo', 'Bar';
71 |
72 | This is also helpful for the case where a package lives within
73 | a differently named file:
74 |
75 | package MyHash;
76 | use Tie::Hash;
77 | use parent -norequire, 'Tie::StdHash';
78 |
79 | This is equivalent to the following code:
80 |
81 | package MyHash;
82 | require Tie::Hash;
83 | push @ISA, 'Tie::StdHash';
84 |
85 | If you want to load a subclass from a file that C would
86 | not consider an eligible filename (that is, it does not end in
87 | either C<.pm> or C<.pmc>), use the following code:
88 |
89 | package MySecondPlugin;
90 | require './plugins/custom.plugin'; # contains Plugin::Custom
91 | use parent -norequire, 'Plugin::Custom';
92 |
93 | =head1 HISTORY
94 |
95 | This module was forked from L to remove the cruft
96 | that had accumulated in it.
97 |
98 | =head1 CAVEATS
99 |
100 | =head1 SEE ALSO
101 |
102 | L
103 |
104 | =head1 AUTHORS AND CONTRIBUTORS
105 |
106 | Rafaël Garcia-Suarez, Bart Lateur, Max Maischein, Anno Siegel, Michael Schwern
107 |
108 | =head1 MAINTAINER
109 |
110 | Max Maischein C< corion@cpan.org >
111 |
112 | Copyright (c) 2007-10 Max Maischein C<< >>
113 | Based on the idea of C, which was introduced with Perl 5.004_04.
114 |
115 | =head1 LICENSE
116 |
117 | This module is released under the same terms as Perl itself.
118 |
119 | =cut
120 |
--------------------------------------------------------------------------------
/bin/nic.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | my $VER = "2.0";
4 |
5 | use strict;
6 | use warnings;
7 | use FindBin;
8 | use lib "$FindBin::RealBin/lib";
9 |
10 | use Getopt::Long;
11 | use Cwd qw(abs_path getcwd);
12 | use File::Spec;
13 | use File::Find;
14 | use File::Copy;
15 | use User::pwent;
16 | use POSIX qw(getuid);
17 | use Module::Load::Conditional 'can_load';
18 | use Tie::File;
19 |
20 | use NIC::Bridge::Context (PROMPT => \&nicPrompt);
21 | use NIC::Formats::NICTar;
22 | use NIC::NICType;
23 |
24 | # Workaround to allow Find to function on WSL. Currently on WSL without this line nic.pl will fail to find templates.
25 | if($^O eq "linux") {
26 | my $fh;
27 | open($fh, "/proc/version");
28 | $File::Find::dont_use_nlink = grep { /Microsoft/ } <$fh>;
29 | close($fh);
30 | }
31 |
32 | our $savedStdout = *STDOUT;
33 |
34 | my @_dirs = File::Spec->splitdir(abs_path($FindBin::Bin));
35 | $_dirs[$#_dirs]="vendor/templates";
36 | our $_vendortemplatepath = File::Spec->catdir(@_dirs);
37 | $_dirs[$#_dirs]="templates";
38 | our $_templatepath = File::Spec->catdir(@_dirs);
39 | $_dirs[$#_dirs]="mod";
40 | my $_modpath = File::Spec->catdir(@_dirs);
41 | $#_dirs--;
42 | my $_theospath = File::Spec->catdir(@_dirs);
43 |
44 | {
45 | my $_abstheospath = abs_path($_theospath);
46 | my $_cwd = abs_path(Cwd::getcwd());
47 | $_abstheospath .= '/' if $_abstheospath !~ /\/$/;
48 | $_cwd .= '/' if $_cwd !~ /\/$/;
49 | exitWithError("Cowardly refusing to make a project inside \$THEOS ($_abstheospath)") if($_cwd =~ /^$_abstheospath/);
50 | }
51 |
52 | my %CONFIG = (link_theos => 0);
53 | loadConfig();
54 |
55 | my $clean_project_name = "";
56 | my $project_name = "";
57 | my $package_prefix = $CONFIG{'package_prefix'};
58 | $package_prefix = "com.yourcompany" if !$package_prefix;
59 | my $package_name = "";
60 | my $username = $CONFIG{'username'};
61 | $username = "" if !$username;
62 |
63 | my $template = undef;
64 | my $nicfile = undef;
65 |
66 | Getopt::Long::Configure("bundling");
67 |
68 | GetOptions( "packagename|p=s" => \$package_name,
69 | "name|n=s" => \$project_name,
70 | "user|u=s" => \$username,
71 | "nic=s" => \$nicfile,
72 | "template|t=s" => \$template);
73 |
74 | $project_name = $ARGV[0] if($ARGV[0]);
75 |
76 | my $_versionstring = "NIC $VER - New Instance Creator";
77 | print $_versionstring,$/;
78 | print "-" x length($_versionstring),$/;
79 |
80 | my $NIC;
81 | if($nicfile) {
82 | $NIC = _loadNIC($nicfile) if $nicfile && -f $nicfile;
83 | } else {
84 | my @templates = getTemplates();
85 | if(scalar @templates == 0) {
86 | exitWithError("No file specified with --nic and no templates found.");
87 | }
88 |
89 | if($template) {
90 | my @matched = grep { $_->name eq $template } @templates;
91 | $NIC = $matched[0] if(scalar @matched > 0);
92 | }
93 | if(!$NIC) {
94 | $NIC = promptList(undef, "Choose a Template (required)", sub { local $_ = shift; return $_->name; }, @templates);
95 | }
96 | }
97 |
98 | exitWithError("No NIC file loaded.") if !$NIC;
99 |
100 | promptIfMissing(\$project_name, undef, "Project Name (required)");
101 | exitWithError("I can't live without a project name! Aieeee!") if !$project_name;
102 | $clean_project_name = cleanProjectName($project_name);
103 |
104 | $package_name = $package_prefix.".".lc($clean_project_name) if $CONFIG{'skip_package_name'};
105 | promptIfMissing(\$package_name, $package_prefix.".".lc($clean_project_name), "Package Name") unless $NIC->variableIgnored("PACKAGENAME");
106 |
107 | promptIfMissing(\$username, getUserName(), "Author/Maintainer Name") unless $NIC->variableIgnored("USER");
108 |
109 | my $directory = $clean_project_name;
110 | if(-d $directory) {
111 | my $response;
112 | promptIfMissing(\$response, "N", "There's already something in $directory. Continue");
113 | exit 1 if(uc($response) eq "N");
114 | }
115 |
116 | $NIC->variable("FULLPROJECTNAME") = $project_name;
117 | $NIC->variable("PROJECTNAME") = $clean_project_name;
118 | $NIC->variable("PACKAGENAME") = $package_name;
119 | $NIC->variable("USER") = $username;
120 |
121 | if(! -e "control" && ! -e "layout/DEBIAN/control") {
122 | $NIC->addConstraint("package");
123 | }
124 |
125 | foreach my $prompt ($NIC->prompts) {
126 | nicPrompt($NIC, $prompt->{name}, $prompt->{prompt}, $prompt->{default});
127 | }
128 |
129 | my $cwd = abs_path(getcwd());
130 |
131 | # Add theos symlink to the template, if necessary
132 | if($CONFIG{'link_theos'} != 0 && !$NIC->variableIgnored("THEOS")) {
133 | $NIC->addConstraint("link_theos");
134 |
135 | my $template_theos_reference = $NIC->_getContentWithoutCreate("theos");
136 | if(!$template_theos_reference || $template_theos_reference->type == NIC::NICType::TYPE_UNKNOWN) {
137 | print STDERR "[warning] Asked to link theos, but template lacks an optional theos link. Creating one! Contact the author of this template about this issue.",$/;
138 | $NIC->registerSymlink("theos", '@@THEOS_PATH@@');
139 | }
140 |
141 | my $theosLinkPath = $CONFIG{'theos_path'};
142 | $theosLinkPath = readlink("$cwd/theos") if !$theosLinkPath && (-l "$cwd/theos") && !$CONFIG{'ignore_parent_theos'};
143 | $theosLinkPath = "$cwd/theos" if !$theosLinkPath && (-d "$cwd/theos") && !$CONFIG{'ignore_parent_theos'};
144 | $theosLinkPath = $_theospath if !$theosLinkPath;
145 |
146 | # Set @@THEOS@@ to 'theos', so that the project refers to its linked copy of theos.
147 | $NIC->variable("THEOS") = "theos";
148 | $NIC->variable("THEOS_PATH") = $theosLinkPath;
149 | } else {
150 | # Trust that the user knows what he's doing and set @@THEOS@@ to $(THEOS). (or whatever the user prefers)
151 | my $theosLocalName = '$(THEOS)';
152 | $theosLocalName = $CONFIG{"theos_local_name"} if $CONFIG{"theos_local_name"};
153 | $NIC->variable("THEOS") = $theosLocalName;
154 | }
155 |
156 | # Execute control script.
157 | $NIC->exec or exitWithError("Failed to build template '".$NIC->name."'.");
158 |
159 | print "Instantiating ".$NIC->name." in ".$clean_project_name."/...",$/;
160 | my $dirname = $clean_project_name;
161 | $NIC->build($dirname);
162 | chdir($cwd);
163 |
164 | my @makefiles = ("GNUmakefile", "makefile", "Makefile");
165 | my $makefile;
166 | map { $makefile = $_ if -e $_; } @makefiles;
167 | if($makefile) {
168 | tie(my @lines, 'Tie::File', $makefile);
169 | my $hasCommon = 0;
170 | map {$hasCommon++ if /common\.mk/;} @lines;
171 | if($hasCommon > 0) {
172 | my $alreadyHas = 0;
173 | map {$alreadyHas++ if /^\s*SUBPROJECTS.*$dirname/;} @lines;
174 | if($alreadyHas == 0) {
175 | print "Adding '$project_name' as an aggregate subproject in Theos makefile '$makefile'.",$/;
176 | my $newline = "SUBPROJECTS += $dirname";
177 | my $i = 0;
178 | my $aggLine = -1;
179 | map {$aggLine = $i if /aggregate\.mk/; $i++;} @lines;
180 | if($aggLine == -1) {
181 | push(@lines, $newline);
182 | push(@lines, "include \$(THEOS_MAKE_PATH)/aggregate.mk");
183 | } else {
184 | splice(@lines, $aggLine, 0, $newline);
185 | }
186 | }
187 | }
188 | untie(@lines);
189 | } else {
190 | # New project, so create .gitignore
191 | my $gitignore = "$dirname/.gitignore";
192 | open my $fileHandle, ">>", $gitignore or exitWithError("Failed to create $gitignore.");
193 | print $fileHandle ".theos/\npackages/\n.DS_Store\n";
194 | close $fileHandle;
195 | }
196 | print "Done.",$/;
197 |
198 | sub promptIfMissing {
199 | my $vref = shift;
200 | return if(${$vref});
201 |
202 | my $default = shift;
203 | my $prompt = shift;
204 |
205 | if($default) {
206 | print $::savedStdout $prompt, " [$default]: ";
207 | } else {
208 | print $::savedStdout $prompt, ": ";
209 | }
210 |
211 | $| = 1; $_ = ;
212 | chomp;
213 |
214 | if($default) {
215 | ${$vref} = $_ ? $_ : $default;
216 | } else {
217 | ${$vref} = $_;
218 | }
219 | }
220 |
221 | sub promptList {
222 | my $default = shift;
223 | my $prompt = shift;
224 | my $formatsub = shift // sub { shift; };
225 | my @list = @_;
226 |
227 | $default = -1 if(!defined $default);
228 |
229 | for(0..$#list) { print " ".($_==$default?">":" ")."[".($_+1).".] ",$formatsub->($list[$_]),$/; }
230 | print $prompt,": ";
231 | $| = 1;
232 | my $idx = -1;
233 | while() {
234 | chomp;
235 | if($default > -1 && $_ eq "") {
236 | $idx = $default;
237 | last;
238 | }
239 | if($_ < 1 || $_ > $#list+1) {
240 | print "Invalid value.",$/,$prompt,": ";
241 | next;
242 | }
243 | $idx = $_-1;
244 | last;
245 | }
246 | return $list[$idx];
247 | }
248 |
249 | sub exitWithError {
250 | my $error = shift;
251 | print STDERR "[error] ", $error, $/;
252 | exit 1;
253 | }
254 |
255 | sub _loadNIC {
256 | my $nicfile = shift;
257 | open(my $nichandle, "<", $nicfile);
258 | my $line = <$nichandle>;
259 | seek($nichandle, 0, 0);
260 |
261 | (my $prettyname = $nicfile) =~ s/$::_templatepath\/(.*)\.nic(\.tar)?/$1/g;
262 | $prettyname .= " (unnamed template)";
263 |
264 | my $nicversion = 1;
265 | my $NIC = undef;
266 | if($line =~ /^nic (\w+)$/) {
267 | $nicversion = $1;
268 | my $NICPackage = "NIC$nicversion";
269 | return undef if(!can_load(modules => {"NIC::Formats::$NICPackage" => undef}));
270 | $NIC = "NIC::Formats::$NICPackage"->new($nichandle, $prettyname);
271 | } else {
272 | $NIC = NIC::Formats::NICTar->new($nichandle, $prettyname);
273 | }
274 |
275 | close($nichandle);
276 | return $NIC;
277 | }
278 |
279 | sub getTemplates {
280 | our @templates = ();
281 | find({wanted => \&templateWanted, no_chdir => 1}, $_vendortemplatepath);
282 | find({wanted => \&templateWanted, no_chdir => 1}, $_templatepath);
283 | foreach my $mod (<$_modpath/*>) {
284 | my $mod_templates = "$mod/templates";
285 | if(-d $mod_templates) {
286 | find({wanted => \&templateWanted, no_chdir => 1}, $mod_templates);
287 | }
288 | }
289 | sub templateWanted {
290 | if(-f && (/\.nic$/ || /\.nic\.tar$/)) {
291 | my $nic = _loadNIC($_);
292 | push(@templates, $nic) if $nic;
293 | }
294 | }
295 | return sort { $a->name cmp $b->name } @templates;
296 | }
297 |
298 | sub cleanProjectName {
299 | my $name = shift;
300 | $name =~ s/[^a-zA-Z0-9+.-]//g;
301 | return $name;
302 | }
303 |
304 | sub getUserName {
305 | my $pw = getpw(getuid());
306 | my ($fullname) = split(/\s*,\s*/, $pw->gecos);
307 | return $fullname && $fullname ne "\"\"" ? $fullname : $pw->name;
308 | }
309 |
310 | sub getHomeDir {
311 | my $pw = getpw(getuid());
312 | return $pw->dir;
313 | }
314 |
315 | sub loadConfig {
316 | open(my $cfh, "<", getHomeDir()."/.nicrc") or return;
317 | while(<$cfh>) {
318 | # Grab config key-value pairs
319 | # Match irrespective of leading whitespace
320 | if(/^\s*(.+?)\s*=\s*\"(.*)\"$/) {
321 | my $key = $1;
322 | my $value = $2;
323 | $CONFIG{$key} = $value;
324 | }
325 | }
326 | close($cfh);
327 | }
328 |
329 | sub nicPrompt {
330 | # Do we want to import these variables into the NIC automatically? In the format name.VARIABLE?
331 | # If so, this could become awesome. We could $NIC->get($prompt->{name})
332 | # and have loaded the variables in a loop beforehand.
333 | # This would also allow the user to set certain variables (package prefix, username) for different templates.
334 | my ($nic, $variable, $prompt, $default) = @_;
335 | my $response = undef;
336 | $response = $CONFIG{$nic->name().".".$variable} if($variable);
337 |
338 | promptIfMissing(\$response, $default, "[".$nic->name."] ".$prompt);
339 |
340 | $NIC->variable($variable) = $response if $variable;
341 |
342 | # Return the response for anybody who's interested.
343 | $response;
344 | }
345 |
--------------------------------------------------------------------------------
/bin/nicify.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | use strict;
4 | use warnings;
5 | use File::Find;
6 | use File::Spec;
7 | use Archive::Tar;
8 | use Cwd qw(abs_path getcwd);
9 |
10 | use FindBin;
11 | use lib "$FindBin::RealBin/lib";
12 | use NIC::Formats::NICTar;
13 |
14 | package NIC::Archive::Tar::File;
15 | use parent "Archive::Tar::File";
16 | sub new {
17 | my $class = shift;
18 | my $self = Archive::Tar::File->new(@_);
19 | bless($self, $class);
20 | return $self;
21 | }
22 |
23 | sub _prefix_and_file {
24 | my $self = shift;
25 | my $path = shift;
26 | my ($prefix, $file) = $self->SUPER::_prefix_and_file($path);
27 | $prefix =~ s/^/\.\// if $prefix ne "" && $prefix ne "." && $prefix !~ /^\.\//;
28 | return ($prefix, $file);
29 | }
30 | 1;
31 | package main;
32 |
33 | if(@ARGV == 0) {
34 | exitWithError("Syntax: $FindBin::Script ");
35 | }
36 |
37 | my $cwd = abs_path(getcwd());
38 | my $tar = Archive::Tar->new();
39 | my $controlfile = undef;
40 | our @tarfiles = (
41 | NIC::Archive::Tar::File->new(data=>"./", "", {type=>Archive::Tar::Constant::DIR, uid=>0, gid=>0, mode=>0755}),
42 | NIC::Archive::Tar::File->new(data=>"./NIC/", "", {type=>Archive::Tar::Constant::DIR, uid=>0, gid=>0, mode=>0777})
43 | );
44 |
45 | chdir $ARGV[0];
46 |
47 | my $control_in = undef;
48 |
49 | if(-f "pre.NIC") {
50 | warning("Using legacy pre.NIC as ./NIC/control.");
51 | $control_in = "./pre.NIC";
52 | } elsif(-f "NIC/control") {
53 | $control_in = "./NIC/control";
54 | }
55 |
56 | if(!$control_in) {
57 | exitWithError("No control file found at NIC/control.");
58 | exit 1;
59 | }
60 |
61 | $controlfile = NIC::Archive::Tar::File->new(file=>$control_in);
62 | $controlfile->prefix("./NIC");
63 | $controlfile->name("control");
64 | push(@tarfiles, $controlfile);
65 |
66 | find({wanted => \&wanted, preprocess => \&preprocess, follow => 0, no_chdir => 1}, ".");
67 |
68 | $tar->add_files(@tarfiles);
69 |
70 | chdir($cwd);
71 | my $newnic = NIC::Formats::NICTar->new($tar);
72 | if(!defined $newnic->name) {
73 | exitWithError("Template has no name. Please insert a `name \"\"` directive into $control_in.");
74 | }
75 |
76 | { my $contents = scalar @{$newnic->{CONTENTS}}; info("$contents entr".($contents==1?"y.":"ies.")); }
77 | { my $prompts = scalar @{$newnic->{PROMPTS}}; info("$prompts prompt".($prompts==1?".":"s.")); }
78 | {
79 | my %constrainthash = ();
80 | for(@{$newnic->{CONTENTS}}) {
81 | for my $c ($_->constraints) {
82 | $constrainthash{$c}++;
83 | }
84 | }
85 | my $constraints = scalar keys %constrainthash;
86 | info("$constraints constraint".($constraints==1?".":"s."));
87 | }
88 |
89 | my $fixedfn = join("_", File::Spec->splitdir($newnic->name));
90 | my $filename = $fixedfn.".nic.tar";
91 | $tar->write($filename) and info("Archived template \"".$newnic->name."\" to $filename.");
92 |
93 | sub preprocess {
94 | my @list = @_;
95 | if($File::Find::dir eq "./NIC") {
96 | @list = grep !/^control$/, @list;
97 | }
98 | @list = grep !/^pre.NIC$/ && !/^\.svn$/ && !/^\.git$/ && !/^_MTN$/ && !/\.nic\.tar$/ && !/^\.DS_Store$/ && !/^\._/, @list;
99 | return @list;
100 | }
101 |
102 | sub wanted {
103 | local $_ = $File::Find::name;
104 | my $mode = (stat)[2];
105 |
106 | my $tarfile = undef;
107 | if(-d) {
108 | s/$/\// if !/\/$/;
109 | return if /^\.\/$/;
110 | return if /^\.\/NIC\/?$/;
111 | $tarfile = NIC::Archive::Tar::File->new(data=>$_, "", {mode=>$mode, uid=>0, gid=>0, type=>Archive::Tar::Constant::DIR});
112 | } elsif(-f && ! -l) {
113 | $tarfile = NIC::Archive::Tar::File->new(file=>$_);
114 | $tarfile->mode($mode);
115 | $tarfile->uid(0);
116 | $tarfile->gid(0);
117 | } elsif(-l) {
118 | $tarfile = NIC::Archive::Tar::File->new(data=>$_, "", {linkname=>readlink($_), uid=>0, gid=>0, type=>Archive::Tar::Constant::SYMLINK});
119 | }
120 | push(@tarfiles, $tarfile) if $tarfile;
121 | }
122 |
123 | sub slurp {
124 | my $fn = shift;
125 | open(my($fh), "<", $fn);
126 | local $/ = undef;
127 | my $d = <$fh>;
128 | return $d;
129 | }
130 |
131 | sub info {
132 | my $text = shift;
133 | print STDERR "[info] ", $text, $/;
134 | }
135 |
136 | sub warning {
137 | my $text = shift;
138 | print STDERR "[warning] ", $text, $/;
139 | }
140 |
141 | sub exitWithError {
142 | my $error = shift;
143 | print STDERR "[error] ", $error, $/;
144 | exit 1;
145 | }
146 |
147 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@theosdev/nic",
3 | "version": "1.0.0",
4 | "description": "Logos is a Perl regex-based preprocessor that simplifies the boilerplate code needed to create hooks for Objective-C methods and C functions with an elegant Objective-C-like syntax.",
5 | "author": "Theos",
6 | "license": "GPL-3.0",
7 | "homepage": "https://theos.github.io/",
8 | "bugs": "https://github.com/theos/nic/issues",
9 |
10 | "repository": {
11 | "type": "git",
12 | "url": "git+https://github.com/theos/nic.git"
13 | },
14 |
15 | "keywords": [
16 | "language",
17 | "ios",
18 | "iphone",
19 | "mac",
20 | "jailbreak",
21 | "objc"
22 | ],
23 |
24 | "bin": {
25 | "nic": "bin/nic.pl",
26 | "nicify": "bin/nicify.pl",
27 | "denicify": "bin/denicify.pl"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/templates/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theos/nic/8ce35a5c5844dc7c74ace84657b6d70b0ff481dd/templates/.keep
--------------------------------------------------------------------------------