# Template::Stash::XS
📦 std
The compiled stash of the Template Toolkit: `get` and `set`, which
resolve a template variable such as `user.name` or `list.0.size`
against the stash’s data.
A dotted variable is walked one element at a time: a hash key, a list
index, an object method, a code reference called with its arguments,
or a virtual method. `size`, `max`, `reverse` and `join` on a list,
`keys`, `values` and `each` on a hash, and `length` and `defined` on a
scalar are compiled; every other virtual method comes from
`Template::Stash`’s `%LIST_OPS`, `%HASH_OPS` and `%SCALAR_OPS`.
This is a native implementation of the `Stash.xs` of Template Toolkit
3.106; its `Template/Stash/XS.pm` is used unchanged, and the Template
Toolkit itself comes from CPAN. It is the stash the Template Toolkit
uses by default.
## Synopsis
```perl
use Template;
use Template::Stash::XS;
my $stash = Template::Stash::XS->new({ user => { name => 'Ann' } });
print $stash->get('user.name'), "\n"; # Ann
$stash->set('user.mail', 'ann@example.org');
my $tt = Template->new({ STASH => $stash });
```
## Differences from upstream
- An object method that dies «Can’t locate object method» no longer
removes a value from the caller’s argument list: after the third
such method in one dotted variable, perl overwrites the caller’s
arguments, so `f('A', 'B', 'C', 'D', $stash->get('x.k.k.k.v'))`
passes the error text in place of `'D'`.
- `set` called with a root that is not a reference dies «don’t know
how to assign to [ ].key»; perl reads the root as if it were a
reference and crashes for undef, a number or a long string.
## Functions
### Template Toolkit
#### [`get`](XS/get.md)
The value of a template variable: `$ident` is a name, a dotted name such as `'user.name'` (arguments in parentheses are dropped), or a list `[ name => \@args, name => \@args, ... ]`; `\@args` as a third argument is passed to a plain name that is a code ref or method.
#### [`set`](XS/set.md)
Assign `$value` to a template variable named as for `get`, creating the hashes on the way; with a true fourth argument, only when the variable is not already true. Returns the value assigned, or an empty string when nothing was.