1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML::Mason::Component - Mason Component Class</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<p><A NAME="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><A HREF="#name">NAME</a></li>
<li><A HREF="#synopsis">SYNOPSIS</a></li>
<li><A HREF="#description">DESCRIPTION</a></li>
<ul>
<li><A HREF="#creating_and_accessing_component">CREATING AND ACCESSING COMPONENTS</a></li>
</ul>
<li><A HREF="#methods">METHODS</a></li>
<li><A HREF="#filebased_methods">FILE-BASED METHODS</a></li>
<li><A HREF="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><A NAME="name">NAME</a></h1>
<p>HTML::Mason::Component - Mason Component Class</p>
<p>
</p>
<hr />
<h1><A NAME="synopsis">SYNOPSIS</a></h1>
<pre>
my $comp1 = $m->current_comp;
my $comp2 = $m->callers(1);
my $comp3 = $m->fetch_comp('foo/bar');</pre>
<pre>
foreach ($comp1,$comp2,$comp3) {
print "My name is ".$_->title.".\n";
}</pre>
<p>
</p>
<hr />
<h1><A NAME="description">DESCRIPTION</a></h1>
<p>Mason uses the Component class to store components loaded into
memory. Components come from three distinct sources:</p>
<ol>
<li>
<p>File-based: loaded from a source or object file.</p>
</li>
<li>
<p>Subcomponents: embedded components defined with the <code><%def></code>
or <code><%method></code> tags.</p>
</li>
<li>
<p>Anonymous: created on-the-fly with the <code>make_component</code> Interp method.</p>
</li>
</ol>
<p>Some of the methods below return different values (or nothing at all)
depending on the component type.</p>
<p>The component API is primarily useful for introspection, e.g. ``what
component called me'' or ``does the next component take a certain
argument''. You can build complex Mason sites without ever dealing
directly with a component object.</p>
<p>
</p>
<h2><A NAME="creating_and_accessing_component">CREATING AND ACCESSING COMPONENTS</a></h2>
<p>Common ways to get handles on existing component objects include the
<A HREF="Request.html#item_current_comp">Request->current_comp</a>,
<A HREF="Request.html#item_callers">Request->callers</a>, and
<A HREF="Request.html#item_fetch_comp">Request->fetch_comp</a> methods.</p>
<p>There is no published <code>new</code> method, because creating a component
requires an Interpreter. Use the
<A HREF="Interp.html#item_make_component">make_component</a> method to
create a new component dynamically.</p>
<p>Similarly, there is no <code>execute</code> or <code>call</code> method, because calling a
component requires a request. All of the interfaces for calling a
component (<& &>, <code>$m-</code>comp>, <code>$interp->exec</code>)
which normally take a component path will also take a component
object.</p>
<p>
</p>
<hr />
<h1><A NAME="methods">METHODS</a></h1>
<dl>
<dt><strong><A NAME="item_attr">attr (name)</a></strong>
<dd>
<p>Looks for the specified attribute in this component and its parents,
returning the first value found. Dies with an error if not
found. Attributes are declared in the <code><%attr></code> section.</p>
</dd>
</li>
<dt><strong><A NAME="item_attr_if_exists">attr_if_exists (name)</a></strong>
<dd>
<p>This method works exactly like the one above but returns undef if the
attribute does not exist.</p>
</dd>
</li>
<dt><strong><A NAME="item_attr_exists">attr_exists (name)</a></strong>
<dd>
<p>Returns true if the specified attribute exists in this component or
one of its parents, undef otherwise.</p>
</dd>
</li>
<dt><strong><A NAME="item_attributes">attributes</a></strong>
<dd>
<p>Returns a hashref containing the attributes defined in this component,
with the attribute names as keys. This does not return attributes
inherited from parent components.</p>
</dd>
</li>
<dt><strong><A NAME="item_call_method">call_method (name, args...)</a></strong>
<dd>
<p>Looks for the specified user-defined method in this component and its
parents, calling the first one found. Dies with an error if not found.
Methods are declared in the <code><%method></code> section.</p>
</dd>
</li>
<dt><strong><A NAME="item_create_time">create_time</a></strong>
<dd>
<p>A synonym for <A HREF="Component.html#item_load_time">load_time</a> (deprecated).</p>
</dd>
</li>
<dt><strong><A NAME="item_declared_args">declared_args</a></strong>
<dd>
<p>Returns a reference to a hash of hashes representing the arguments
declared in the <code><%args></code> section. The keys of the main hash are the
variable names including prefix (e.g. <code>$foo</code>, <code>@list</code>). Each
secondary hash contains:</p>
</dd>
<ul>
<li>
<p>'default': the string specified for default value (e.g. 'fido') or undef
if none specified. Note that in general this is not the default value
itself but rather a Perl expression that gets evaluated every time the
component runs.</p>
</li>
</ul>
<p>For example:</p>
<pre>
# does $comp have an argument called $fido?
if (exists($comp->declared_args->{'$fido'})) { ... }</pre>
<pre>
# does $fido have a default value?
if (defined($comp->declared_args->{'$fido'}->{default})) { ... }</pre>
<dt><strong><A NAME="item_dir_path">dir_path</a></strong>
<dd>
<p>Returns the component's notion of a current directory, relative to the
component root; this is used to resolve relative component paths. For
file-based components this is the full component path minus the filename.
For subcomponents this is the same as the component that defines it.
Undefined for anonymous components.</p>
</dd>
</li>
<dt><strong><A NAME="item_flag">flag (name)</a></strong>
<dd>
<p>Returns the value for the specified system flag. Flags are declared
in the <code><%flags></code> section and affect the behavior of the component.
Unlike attributes, flags values do not get inherited from parent components.</p>
</dd>
</li>
<dt><strong><A NAME="item_is_subcomp">is_subcomp</a></strong>
<dd>
<p>Returns true if this is a subcomponent of another component. For
historical reasons, this returns true for both methods and
subcomponents.</p>
</dd>
</li>
<dt><strong><A NAME="item_is_method">is_method</a></strong>
<dd>
<p>Returns true if this is a method.</p>
</dd>
</li>
<dt><strong><A NAME="item_is_file_based">is_file_based</a></strong>
<dd>
<p>Returns true if this component was loaded from a source or object
file.</p>
</dd>
<A NAME="item_load_time"></a></li>
<dt><strong><A NAME="item_load_time">load_time</a></strong>
<dd>
<p>Returns the time (in Perl <code>time()</code> format) when this component object
was created.</p>
</dd>
</li>
<dt><strong><A NAME="item_method_exists">method_exists (name)</a></strong>
<dd>
<p>Returns true if the specified user-defined method exists in this
component or one of its parents, undef otherwise.</p>
</dd>
</li>
<dt><strong><A NAME="item_methods">methods</a></strong>
<dd>
<p>This method works exactly like the
<A HREF="Component.html#item_subcomps">subcomps</a> method, but it
returns methods, not subcomponents. This does not return methods
inherited from parent components.</p>
</dd>
<dd>
<p>Methods are declared in <code><%method></code> sections.</p>
</dd>
</li>
<dt><strong><A NAME="item_name">name</a></strong>
<dd>
<p>Returns a short name of the component. For file-based components this
is the filename without the path. For subcomponents this is the name
specified in <code><%def></code>. Undefined for anonymous components.</p>
</dd>
</li>
<dt><strong><A NAME="item_object_file">object_file</a></strong>
<dd>
<p>Returns the object filename for this component.</p>
</dd>
</li>
<dt><strong><A NAME="item_parent">parent</a></strong>
<dd>
<p>Returns the parent of this component for inheritance purposes, by
default the nearest <code>autohandler</code> in or above the component's directory.
Can be changed via the <code>inherit</code> flag.</p>
</dd>
</li>
<dt><strong><A NAME="item_path">path</a></strong>
<dd>
<p>Returns the entire path of this component, relative to the component root.</p>
</dd>
</li>
<dt><strong><A NAME="item_scall_method">scall_method (name, args...)</a></strong>
<dd>
<p>Like <A HREF="#item_call_method">item_call_method</a>, but returns the method output as
a string instead of printing it. (Think sprintf versus printf.) The
method's return value, if any, is discarded.</p>
</dd>
<A NAME="item_subcomps"></a></li>
<dt><strong><A NAME="item_subcomps">subcomps</a></strong>
<dd>
<p>With no arguments, returns a hashref containing the subcomponents defined
in this component, with names as keys and component objects as values.
With one argument, returns the subcomponent of that name
or undef if no such subcomponent exists. e.g.</p>
</dd>
<dd>
<pre>
if (my $subcomp = $comp->subcomps('.link')) {
...
}</pre>
</dd>
<dd>
<p>Subcomponents are declared in <code><%def></code> sections.</p>
</dd>
</li>
<dt><strong><A NAME="item_title">title</a></strong>
<dd>
<p>Returns a printable string denoting this component. It is intended to
uniquely identify a component within a given interpreter although this
is not 100% guaranteed. Mason uses this string in error messages,
among other places.</p>
</dd>
<dd>
<p>For file-based components this is the component path. For
subcomponents this is ``parent_component_path:subcomponent_name''. For
anonymous components this is a unique label like ``[anon 17]''.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><A NAME="filebased_methods">FILE-BASED METHODS</a></h1>
<p>The following methods apply only to file-based components (those
loaded from source or object files). They return undef for other
component types.</p>
<dl>
<dt><strong><A NAME="item_source_file">source_file</a></strong>
<dd>
<p>Returns the source filename for this component.</p>
</dd>
</li>
<dt><strong><A NAME="item_source_dir">source_dir</a></strong>
<dd>
<p>Returns the directory of the source filename for this component.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><A NAME="see_also">SEE ALSO</a></h1>
<p><a HREF="Mason.html">HTML::Mason</a>,
<a HREF="Devel.html">HTML::Mason::Devel</a>,
<a HREF="Request.html">HTML::Mason::Request</a></p>
</body>
</html>
|