@barefootjs/cli 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
- [Adapter Architecture](./adapters/adapter-architecture.md) — How adapters work, the `TemplateAdapter` interface, and the IR contract
|
|
53
53
|
- [Hono Adapter](./adapters/hono-adapter.md) — Configuration and output format for Hono / JSX-based servers
|
|
54
54
|
- [Go Template Adapter](./adapters/go-template-adapter.md) — Configuration and output format for Go `html/template`
|
|
55
|
+
- [Perl Adapter](./adapters/perl-adapter.md) — Mojolicious and Text::Xslate (PSGI/Plack) backends, sharing one runtime
|
|
55
56
|
- [CSR (Client-Side Rendering)](./adapters/csr.md) — Static-hosting renderer: emit client JS only, no SSR template
|
|
56
57
|
- [Writing a Custom Adapter](./adapters/custom-adapter.md) — Step-by-step guide to implementing your own adapter
|
|
57
58
|
|
|
@@ -72,8 +73,8 @@ Code examples use **switchable tabs** for adapter output and package manager com
|
|
|
72
73
|
|
|
73
74
|
<Tabs id="adapter" labels="Hono (default),Go Template" />
|
|
74
75
|
|
|
75
|
-
**Package Manager** — npm (default), bun, pnpm, or
|
|
76
|
+
**Package Manager** — npm (default), bun, pnpm, yarn, or deno:
|
|
76
77
|
|
|
77
|
-
<Tabs id="pm" labels="npm (default),bun,pnpm,yarn" />
|
|
78
|
+
<Tabs id="pm" labels="npm (default),bun,pnpm,yarn,deno" />
|
|
78
79
|
|
|
79
80
|
> Sections marked with 💡 explain JSX and TypeScript concepts for developers from Go, Python, or other backend languages.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Perl Adapter
|
|
3
|
+
description: Render BarefootJS components from Perl — one engine-agnostic runtime with Mojolicious and Text::Xslate (PSGI/Plack) backends.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Perl Adapter
|
|
7
|
+
|
|
8
|
+
Run the same JSX components on a Perl backend. BarefootJS compiles your JSX into
|
|
9
|
+
a **marked template** plus **client JS**; on the server, a small Perl runtime
|
|
10
|
+
renders those templates. The runtime is deliberately **template-engine- and
|
|
11
|
+
web-framework-agnostic**, so one implementation drives multiple stacks.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
JSX → IR → marked template (.ep / .tx) + Component.client.js
|
|
15
|
+
│
|
|
16
|
+
▼
|
|
17
|
+
BarefootJS runtime ──delegates──▶ pluggable backend
|
|
18
|
+
(@barefootjs/perl) (Mojolicious | Text::Xslate)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Two backends, one runtime
|
|
22
|
+
|
|
23
|
+
| Backend | Template syntax | Compile-time package | Runtime | Where it runs |
|
|
24
|
+
|---------|-----------------|----------------------|---------|---------------|
|
|
25
|
+
| Mojolicious | EP (`<%= %>`) | `@barefootjs/mojolicious` | `Mojolicious::Plugin::BarefootJS` + `BarefootJS::Backend::Mojo` | Mojolicious apps |
|
|
26
|
+
| Text::Xslate | Kolon (`<: :>`) | `@barefootjs/xslate` | `BarefootJS::Backend::Xslate` | **any PSGI / Plack app** (no framework) |
|
|
27
|
+
|
|
28
|
+
Both compile-time packages emit per-component template files and the shared
|
|
29
|
+
client JS, and both render through the same engine-agnostic Perl runtime
|
|
30
|
+
(`BarefootJS`, shipped by `@barefootjs/perl`). The only thing that differs is
|
|
31
|
+
the **backend**: a tiny object that implements the four operations the runtime
|
|
32
|
+
delegates to.
|
|
33
|
+
|
|
34
|
+
### The backend contract
|
|
35
|
+
|
|
36
|
+
Everything that depends on *how* a template renders — JSON marshalling,
|
|
37
|
+
raw-string marking, JSX-children materialisation, and named-template
|
|
38
|
+
rendering — lives behind a `backend` object with four methods:
|
|
39
|
+
|
|
40
|
+
| Method | Purpose |
|
|
41
|
+
|--------|---------|
|
|
42
|
+
| `encode_json($data)` | Serialize a value for `bf-p` props / inline JSON |
|
|
43
|
+
| `mark_raw($str)` | Mark already-safe HTML so the engine won't re-escape it |
|
|
44
|
+
| `materialize($value)` | Resolve captured JSX children to a string |
|
|
45
|
+
| `render_named($name, $bf, \%vars)` | Render a child component's template |
|
|
46
|
+
|
|
47
|
+
Because that is the *only* engine-specific surface, the EP→Kolon mapping is
|
|
48
|
+
mechanical and the runtime is reused unchanged:
|
|
49
|
+
|
|
50
|
+
| Mojolicious EP | Text::Xslate Kolon |
|
|
51
|
+
|----------------|--------------------|
|
|
52
|
+
| `<%= EXPR %>` (escaped) | `<: EXPR :>` (Kolon auto-escapes) |
|
|
53
|
+
| `<%== EXPR %>` (raw) | `<: EXPR \| mark_raw :>` |
|
|
54
|
+
| `bf->method(args)` | `$bf.method(args)` |
|
|
55
|
+
| `% if (C) { … % }` | `: if (C) { … : }` |
|
|
56
|
+
|
|
57
|
+
## Mojolicious
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
npm install @barefootjs/mojolicious
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Scaffold a runnable starter:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
npm create barefootjs@latest -- --adapter mojo
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Configure the build (`barefoot.config.ts`):
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { createConfig } from '@barefootjs/mojolicious/build'
|
|
73
|
+
|
|
74
|
+
export default createConfig({
|
|
75
|
+
components: ['./components'],
|
|
76
|
+
outDir: 'dist',
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
In your app, load the plugin — it registers a `bf` helper that gives each
|
|
81
|
+
request a `BarefootJS` runtime backed by `BarefootJS::Backend::Mojo`:
|
|
82
|
+
|
|
83
|
+
```perl
|
|
84
|
+
use Mojolicious::Lite -signatures;
|
|
85
|
+
|
|
86
|
+
plugin 'BarefootJS';
|
|
87
|
+
|
|
88
|
+
get '/counter' => sub ($c) {
|
|
89
|
+
$c->render(template => 'Counter', layout => 'default');
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
app->start;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The generated `.html.ep` templates call the runtime through the `bf` helper
|
|
96
|
+
(`<%== bf->scope_attr %>`, `<%= bf->json($data) %>`, …).
|
|
97
|
+
|
|
98
|
+
## Text::Xslate (PSGI / Plack)
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
npm install @barefootjs/xslate
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { createConfig } from '@barefootjs/xslate/build'
|
|
106
|
+
|
|
107
|
+
export default createConfig({
|
|
108
|
+
components: ['./components'],
|
|
109
|
+
outDir: 'dist',
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The build emits Kolon `.tx` templates. The backend is just a plain
|
|
114
|
+
`Text::Xslate` instance, so it runs under **any PSGI/Plack app** — no
|
|
115
|
+
Mojolicious required:
|
|
116
|
+
|
|
117
|
+
```perl
|
|
118
|
+
use BarefootJS;
|
|
119
|
+
use BarefootJS::Backend::Xslate;
|
|
120
|
+
|
|
121
|
+
my $backend = BarefootJS::Backend::Xslate->new(path => ['dist/templates']);
|
|
122
|
+
|
|
123
|
+
my $app = sub {
|
|
124
|
+
my $env = shift;
|
|
125
|
+
my $bf = BarefootJS->new(undef, { backend => $backend });
|
|
126
|
+
$bf->_scope_id('Counter_' . int(rand(1e6)));
|
|
127
|
+
my $body = $backend->render_named('Counter', $bf, { count => 0 });
|
|
128
|
+
my $html = "<!doctype html><body>$body" . $bf->scripts . '</body>';
|
|
129
|
+
return [200, ['Content-Type' => 'text/html; charset=utf-8'], [$html]];
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The generated Kolon templates call the runtime as a `bf` object
|
|
134
|
+
(`<: $bf.scope_attr() :>`, `<: $bf.json($data) :>`, …). Kolon auto-escapes
|
|
135
|
+
`<: … :>` interpolations; helpers that emit markup return `mark_raw` values.
|
|
136
|
+
|
|
137
|
+
## CPAN distributions
|
|
138
|
+
|
|
139
|
+
The Perl side is packaged as standalone CPAN distributions (built with
|
|
140
|
+
[Minilla](https://metacpan.org/pod/Minilla)), so a Perl app can depend on them
|
|
141
|
+
without the JS toolchain at runtime:
|
|
142
|
+
|
|
143
|
+
| Distribution | Main module | Depends on |
|
|
144
|
+
|--------------|-------------|------------|
|
|
145
|
+
| `BarefootJS` | `BarefootJS` | core Perl only |
|
|
146
|
+
| `BarefootJS-Backend-Xslate` | `BarefootJS::Backend::Xslate` | `BarefootJS`, `Text::Xslate` |
|
|
147
|
+
| `Mojolicious-Plugin-BarefootJS` | `Mojolicious::Plugin::BarefootJS` | `BarefootJS`, `Mojolicious` |
|
|
148
|
+
|
|
149
|
+
## Dev auto-reload
|
|
150
|
+
|
|
151
|
+
`barefoot build --watch` writes a sentinel after each rebuild; the browser can
|
|
152
|
+
subscribe to a small SSE endpoint and reload automatically. The logic is
|
|
153
|
+
framework-agnostic (`BarefootJS::DevReload`):
|
|
154
|
+
|
|
155
|
+
- **Mojolicious:** `plugin 'BarefootJS::DevReload'`, then emit `%== bf_dev_snippet` before `</body>`.
|
|
156
|
+
- **PSGI / Plack:** mount `BarefootJS::DevReload->to_app(dist_dir => 'dist')` at the SSE endpoint, and emit `BarefootJS::DevReload->snippet($endpoint)` in your layout. Run under a prefork server (Starman / Starlet) in dev.
|
|
157
|
+
|
|
158
|
+
Both are no-ops in production.
|
|
159
|
+
|
|
160
|
+
## Examples
|
|
161
|
+
|
|
162
|
+
Runnable end-to-end apps that render the same shared components on a Perl
|
|
163
|
+
backend live under
|
|
164
|
+
[`integrations/`](https://github.com/piconic-ai/barefootjs/tree/main/integrations) —
|
|
165
|
+
including SSR, fine-grained reactivity, a REST todo API, and SSE streaming.
|
|
166
|
+
|
|
167
|
+
## See also
|
|
168
|
+
|
|
169
|
+
- [Adapter Architecture](./adapter-architecture.md) — the `TemplateAdapter` interface and IR contract
|
|
170
|
+
- [Backend Freedom](../core-concepts/backend-freedom.md) — why the same JSX runs on any stack
|
|
171
|
+
- [Writing a Custom Adapter](./custom-adapter.md)
|
|
@@ -22,12 +22,15 @@ JSX Source
|
|
|
22
22
|
|---------|--------|---------|---------|
|
|
23
23
|
| [`HonoAdapter`](./adapters/hono-adapter.md) | `.tsx` | Hono / JSX-based servers | `@barefootjs/hono` |
|
|
24
24
|
| [`GoTemplateAdapter`](./adapters/go-template-adapter.md) | `.tmpl` + `_types.go` | Go `html/template` | `@barefootjs/go-template` |
|
|
25
|
+
| [Perl](./adapters/perl-adapter.md) | `.ep` / `.tx` | Mojolicious, Text::Xslate (PSGI/Plack) | `@barefootjs/mojolicious`, `@barefootjs/xslate` |
|
|
25
26
|
| [CSR](./adapters/csr.md) | — (client-rendered) | None (browser-only) | `@barefootjs/client` |
|
|
26
27
|
|
|
27
28
|
> CSR is not an IR→template adapter. It renders components directly in the browser using client-side template functions — use it when the server can't (or shouldn't) emit the initial HTML.
|
|
28
29
|
|
|
29
30
|
The `GoTemplateAdapter` is web-framework-agnostic: its `html/template` output runs on any Go server. `npm create barefootjs@latest` ships scaffolds for Echo, Gin, Chi, and net/http (via `--adapter`) — see [Go Template Adapter → Server integration](./adapters/go-template-adapter.md#server-integration).
|
|
30
31
|
|
|
32
|
+
The Perl adapters share one engine-agnostic runtime (`BarefootJS`): `@barefootjs/mojolicious` targets Mojolicious EP, and `@barefootjs/xslate` targets Text::Xslate (Kolon) and runs under any PSGI/Plack app. See the [Perl Adapter](./adapters/perl-adapter.md) page.
|
|
33
|
+
|
|
31
34
|
## Pages
|
|
32
35
|
|
|
33
36
|
| Topic | Description |
|
|
@@ -35,5 +38,6 @@ The `GoTemplateAdapter` is web-framework-agnostic: its `html/template` output ru
|
|
|
35
38
|
| [Adapter Architecture](./adapters/adapter-architecture.md) | How adapters work, the `TemplateAdapter` interface, and the IR contract |
|
|
36
39
|
| [Hono Adapter](./adapters/hono-adapter.md) | Configuration and output format for Hono / JSX-based servers |
|
|
37
40
|
| [Go Template Adapter](./adapters/go-template-adapter.md) | Configuration and output format for Go `html/template` |
|
|
41
|
+
| [Perl Adapter](./adapters/perl-adapter.md) | Mojolicious and Text::Xslate (PSGI/Plack) backends, sharing one runtime |
|
|
38
42
|
| [CSR](./adapters/csr.md) | Client-side rendering without a server-rendered template |
|
|
39
43
|
| [Writing a Custom Adapter](./adapters/custom-adapter.md) | Step-by-step guide to implementing your own adapter |
|
package/dist/docs/core/llms.txt
CHANGED
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
- [Writing a Custom Adapter](https://barefootjs.dev/docs/adapters/custom-adapter.md): Step-by-step guide to building a custom adapter using the TestAdapter as a reference.
|
|
45
45
|
- [Go Template Adapter](https://barefootjs.dev/docs/adapters/go-template-adapter.md): Generate Go html/template files and type definitions from the compiler's IR.
|
|
46
46
|
- [Hono Adapter](https://barefootjs.dev/docs/adapters/hono-adapter.md): Generate Hono JSX templates from the compiler's IR for Hono-based servers.
|
|
47
|
+
- [Perl Adapter](https://barefootjs.dev/docs/adapters/perl-adapter.md): Render BarefootJS components from Perl — one engine-agnostic runtime with Mojolicious and Text::Xslate (PSGI/Plack) backends.
|
|
47
48
|
|
|
48
49
|
## Advanced
|
|
49
50
|
|
|
@@ -9,7 +9,7 @@ Scaffold a BarefootJS app, run it locally, and tour the generated project. About
|
|
|
9
9
|
|
|
10
10
|
## Prerequisites
|
|
11
11
|
|
|
12
|
-
- **Node.js 22+** (or Bun).
|
|
12
|
+
- **Node.js 22+** (or Bun, or Deno 2+).
|
|
13
13
|
- The default scaffold targets [Cloudflare Workers](https://developers.cloudflare.com/workers/) via `wrangler dev` — runs locally, no account needed.
|
|
14
14
|
|
|
15
15
|
## 1. Scaffold the project
|