NAME
YATT::Lite::Factory - Loader for YATT::Lite
SYNOPSIS
use YATT::Lite::Factory;
my $factory = YATT::Lite::Factory->new(vfs => [dir => $dir]);
my $yatt = $factory->get_yatt('/');
print $yatt->render(index => {title => "Hello!", user => "foobar"});
DESCRIPTION
YATT::Lite::Factory is the site-level object of YATT::Lite: it owns the site-wide configuration (app_root, doc_root, app_base...), creates and caches one YATT::Lite instance (a dirhandler) per template directory, and dispatches execution to them.
In the class hierarchy it sits between the public facade and the web adapter:
YATT::Lite::Site public facade API (documented there)
^ YATT::Lite::Factory site object; per-dir loader (this class)
^ YATT::Lite::WebMVC0::SiteApp Site + PSGI adapter
Programs usually should not construct a Factory directly: open a site through YATT::Lite::Site's load/load_or_default (or, in app.psgi, through load_factory_for_psgi) and use the facade methods. The methods below are the load-bearing pieces documented for subclassers and tool authors.
CLASS METHODS
load_factory_for_psgi($psgi_filename, %opts)
The standard way for app.psgi to create its site object. Derives app_rootname from the script location, reads app.site_config.yml/xhf and sibling config dirs, and returns the configured instance.
load_factory_offline(%opts)
Searches app.psgi/runyatt.psgi upward from $opts{dir} and loads it with offline => 1 (error_handler passes raw die through). Returns nothing when no script is found. Prefer YATT::Lite::Site->load, which adds the per-script cache and a clear error.
METHODS
get_yatt($location)
Returns the dirhandler for a location (like / or /admin), resolved against the template directories. Cached per location.
get_dirhandler($physical_dir)
Returns the dirhandler for a physical directory path (alias of load_yatt). Cached per realpath.
render($reqrec, $args)
print $factory->render('/index', {title => "Hello!"});
Renders one page addressed by path ($reqrec is a path string or [$path, $subpage, $action]) and returns the output as decoded text (bytes when render_as_bytes is set). render_encoded returns raw bytes; render_into($con, $reqrec, $args) writes into an existing connection.
Since GH-267 the render path runs through a common context wrapper: it localizes $SYS/$YATT/$CON, runs before_dirhandler/after_dirhandler (so site_config_as_entity works here too) and holds the chdir guard - but intentionally does not install the __DIE__/__WARN__ traps of the web path: errors propagate as raw die (perl -d friendly). See "EXECUTION CONTRACTS" in YATT::Lite::Site.
run_dirhandler($dh, $con, $file)
The web execution primitive: localizes $SYS/$YATT/$CON, runs the dirhandler hooks and $dh->handle (which installs the __DIE__/__WARN__ traps and the chdir guard). Used by SiteApp::call and Site->render_file.
make_connection($fh, %opts)
Creates a YATT::Lite::Connection bound to this site (system => $factory is added automatically, so $CON->system returns the site).
AUTHOR
"KOBAYASI, Hiroaki" <hkoba@cpan.org>