{
    "mode": "perldoc",
    "parameter": "HTML::Mason::Plugin",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3AMason%3A%3APlugin/json",
    "generated": "2026-06-10T16:26:51Z",
    "sections": {
        "NAME": {
            "content": "HTML::Mason::Plugin - Plugin Base class for Mason\n",
            "subsections": []
        },
        "SYNOPIS": {
            "content": "package MasonX::Plugin::Timer;\nuse base qw(HTML::Mason::Plugin);\nuse Time::HiRes;\n\nsub startcomponenthook {\nmy ($self, $context) = @;\npush @{$self->{ timers }}, Time::HiRes::time;\n}\n\nsub endcomponenthook {\nmy ($self, $context) = @;\nmy $elapsed = Time::HiRes::time - pop @{$self->{ timers }};\nprintf STDERR \"Component '%s' took %.1f seconds\\n\",\n$context->comp->title, $elapsed;\n}\n\n1;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Use a Mason plugin to have actions occur at the beginning or end of requests or components.\nPlugins are activated by passing plugins in the interpreter or request object. Each plugin in\nthe list can be specified as a class name (in which case the plugin object is created once for\neach request) or as an actual object of the plugin class.\n\nIf your plugin can be configured, place the configuration in class variables - for example,\n\n$MasonX::Plugin::Timer::Units = 'seconds';\n\nThese can be set either from httpd.conf via PerlSetVar directives, or in perl directly from a\nhandler.pl file.\n",
            "subsections": []
        },
        "PLUGIN HOOKS": {
            "content": "A plugin class defines one or more of the following hooks (methods): *startrequesthook*,\n*endrequesthook*, *startcomponenthook*, and *endcomponenthook*.\n\nEvery hook receives two arguments: the plugin object itself, and a context object with various\nmethods.\n\nstartrequesthook\n\"startrequesthook\" is called before the Mason request begins execution. Its context has\nthe following read-only methods:\n\nrequest # the current request ($m)\nargs    # arguments the request was called with\n\nWhen called in scalar context, *args* returns a list reference which may be modified to\nchange or add to the arguments passed to the first component. When called in list context,\n*args* returns a list (which may be assigned to a hash).\n\nNote that subrequests (see HTML::Mason::Request will create a new plugin object and execute\nthis code again; you can skip your code for subrequests by checking \"issubrequest\" on\n*request*. e.g.\n\nsub startrequesthook {\nmy ($self, $context) = @;\nunless ($context->request->issubrequest()) {\n# perform hook action\n}\n}\n\nCurrently, this hook is called before any information about the requested component is\navailable, so you cannot call methods like \"basecomp()\" or \"requestargs()\" on the Request\nobject.\n\nendrequesthook\n\"endrequesthook\" is called before the Mason request exits. Its context has the following\nread-only methods:\n\nrequest     # the current request ($m)\nargs        # arguments the request was called with\noutput      # reference to the contents of the output buffer\nwantarray   # value of wantarray the request was called with\nresult      # arrayref of value(s) that the request is about to return\nerror       # reference to error, if any, that the request is about to throw\n\nWhen called in scalar context, *args* returns a list reference; when called in list context,\nit returns a list (which may be assigned to a hash).\n\n*result* always contains an array ref; if *wantarray* is 0, the return value is the the\nfirst element of that array. The plugin may modify *output* to affect what the request\noutputs, and *result* and *error* to affect what the request returns.\n\nstartcomponenthook\n\"startcomponenthook\" is called before a component begins executing. Its context has the\nfollowing read-only methods:\n\nrequest     # the current request ($m)\ncomp        # the component object\nargs        # arrayref of arguments the component was called with\n\nThe plugin may NOT modify *args* currently.\n\nendcomponenthook\n\"endcomponenthook()\" is called after a component has completed. Its context has the\nfollowing read-only methods:\n\nrequest     # the current request ($m)\ncomp        # the component object\nargs        # arrayref of arguments the component was called with\nwantarray   # value of wantarray the component was called with\nresult      # arrayref of value(s) that the component is about to return\nerror       # reference to error, if any, that the component is about to throw\n\n*result* always contains an array ref; if *wantarray* is 0, the return value is the first\nelement of that array. The plugin may modify both *result* and *error* to affect how the\nrequest returns.\n\nIt would be desirable for this hook to have access to the component's output as well as its\nreturn value, but this is currently impossible because output from multiple components\ncombine into a single buffer.\n",
            "subsections": []
        },
        "WARNINGS": {
            "content": "Do not keep an unweakened reference to a request or component object in your plugin object, or\nyou will create a nasty circular reference.\n",
            "subsections": []
        }
    },
    "summary": "HTML::Mason::Plugin - Plugin Base class for Mason",
    "flags": [],
    "examples": [],
    "see_also": []
}