{
    "mode": "perldoc",
    "parameter": "HTML::Mason::Component",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3AMason%3A%3AComponent/json",
    "generated": "2026-06-12T21:16:40Z",
    "synopsis": "my $comp1 = $m->currentcomp;\nmy $comp2 = $m->callers(1);\nmy $comp3 = $m->fetchcomp('foo/bar');\nforeach ($comp1,$comp2,$comp3) {\nprint \"My name is \".$->title.\".\\n\";\n}",
    "sections": {
        "NAME": {
            "content": "HTML::Mason::Component - Mason Component Class\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $comp1 = $m->currentcomp;\nmy $comp2 = $m->callers(1);\nmy $comp3 = $m->fetchcomp('foo/bar');\n\nforeach ($comp1,$comp2,$comp3) {\nprint \"My name is \".$->title.\".\\n\";\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Mason uses the Component class to store components loaded into memory. Components come from\nthree distinct sources:\n\n1   File-based: loaded from a source or object file.\n\n2   Subcomponents: embedded components defined with the \"<%def>\" or \"<%method>\" tags.\n\n3   Anonymous: created on-the-fly with the \"makecomponent\" Interp method.\n\nSome of the methods below return different values (or nothing at all) depending on the component\ntype.\n\nThe component API is primarily useful for introspection, e.g. \"what component called me\" or\n\"does the next component take a certain argument\". You can build complex Mason sites without\never dealing directly with a component object.\n\nCREATING AND ACCESSING COMPONENTS\nCommon ways to get handles on existing component objects include the Request->currentcomp,\nRequest->callers, and Request->fetchcomp methods.\n\nThere is no published \"new\" method, because creating a component requires an Interpreter. Use\nthe makecomponent method to create a new component dynamically.\n\nSimilarly, there is no \"execute\" or \"call\" method, because calling a component requires a\nrequest. All of the interfaces for calling a component (\"<& &>\", \"$m->comp\", \"$interp->exec\")\nwhich normally take a component path will also take a component object.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "attr (name)\nLooks for the specified attribute in this component and its parents, returning the first\nvalue found. Dies with an error if not found. Attributes are declared in the \"<%attr>\"\nsection.\n\nattrifexists (name)\nThis method works exactly like the one above but returns undef if the attribute does not\nexist.\n\nattrexists (name)\nReturns true if the specified attribute exists in this component or one of its parents,\nundef otherwise.\n\nattributes\nReturns a hashref containing the attributes defined in this component, with the attribute\nnames as keys. This does not return attributes inherited from parent components.\n\ncallmethod (name, args...)\nLooks for the specified user-defined method in this component and its parents, calling the\nfirst one found. Dies with an error if not found. Methods are declared in the \"<%method>\"\nsection.\n\ncreatetime\nA synonym for loadtime (deprecated).\n\ndeclaredargs\nReturns a reference to a hash of hashes representing the arguments declared in the \"<%args>\"\nsection. The keys of the main hash are the variable names including prefix (e.g. $foo,\n@list). Each secondary hash contains:\n\n*   'default': the string specified for default value (e.g. 'fido') or undef if none\nspecified. Note that in general this is not the default value itself but rather a Perl\nexpression that gets evaluated every time the component runs.\n\nFor example:\n\n# does $comp have an argument called $fido?\nif (exists($comp->declaredargs->{'$fido'})) { ... }\n\n# does $fido have a default value?\nif (defined($comp->declaredargs->{'$fido'}->{default})) { ... }\n\ndirpath\nReturns the component's notion of a current directory, relative to the component root; this\nis used to resolve relative component paths. For file-based components this is the full\ncomponent path minus the filename. For subcomponents this is the same as the component that\ndefines it. Undefined for anonymous components.\n\nflag (name)\nReturns the value for the specified system flag. Flags are declared in the \"<%flags>\"\nsection and affect the behavior of the component. Unlike attributes, flags values do not get\ninherited from parent components.\n\nissubcomp\nReturns true if this is a subcomponent of another component. For historical reasons, this\nreturns true for both methods and subcomponents.\n\nismethod\nReturns true if this is a method.\n\nisfilebased\nReturns true if this component was loaded from a source or object file.\n\nloadtime\nReturns the time (in Perl time() format) when this component object was created.\n\nmethodexists (name)\nReturns true if the specified user-defined method exists in this component or one of its\nparents, undef otherwise.\n\nmethods\nThis method works exactly like the subcomps method, but it returns methods, not\nsubcomponents. This does not return methods inherited from parent components.\n\nMethods are declared in \"<%method>\" sections.\n\nname\nReturns a short name of the component. For file-based components this is the filename\nwithout the path. For subcomponents this is the name specified in \"<%def>\". Undefined for\nanonymous components.\n\nobjectfile\nReturns the object filename for this component.\n\nparent\nReturns the parent of this component for inheritance purposes, by default the nearest\n\"autohandler\" in or above the component's directory. Can be changed via the \"inherit\" flag.\n\npath\nReturns the entire path of this component, relative to the component root.\n\nscallmethod (name, args...)\nLike itemcallmethod, but returns the method output as a string instead of printing it.\n(Think sprintf versus printf.) The method's return value, if any, is discarded.\n\nsubcomps\nWith no arguments, returns a hashref containing the subcomponents defined in this component,\nwith names as keys and component objects as values. With one argument, returns the\nsubcomponent of that name or undef if no such subcomponent exists. e.g.\n\nif (my $subcomp = $comp->subcomps('.link')) {\n...\n}\n\nSubcomponents are declared in \"<%def>\" sections.\n\ntitle\nReturns a printable string denoting this component. It is intended to uniquely identify a\ncomponent within a given interpreter although this is not 100% guaranteed. Mason uses this\nstring in error messages, among other places.\n\nFor file-based components this is the component path. For subcomponents this is\n\"parentcomponentpath:subcomponentname\". For anonymous components this is a unique label\nlike \"[anon 17]\".\n",
            "subsections": []
        },
        "FILE-BASED METHODS": {
            "content": "The following methods apply only to file-based components (those loaded from source or object\nfiles). They return undef for other component types.\n\nsourcefile\nReturns the source filename for this component.\n\nsourcedir\nReturns the directory of the source filename for this component.\n",
            "subsections": []
        }
    },
    "summary": "HTML::Mason::Component - Mason Component Class",
    "flags": [],
    "examples": [],
    "see_also": []
}