I wanted to add some junk to a cgi app module (A.pm), so I made a module appart (B.pm), with more methods, and runmodes.. aha! And when I import the stuff into my main module.. I get

Invalid CODE attribute: Runmode

I want A.pm to import code in B.pm

A.pm is a CGI::Application app.

I am using CGI::Application::Plugin::AutoRunmode to define runmodes.

I get this error:

Invalid CODE attribute: Runmode

I was importing B.pm code into A.pm by "use base 'B.pm';", so I tried instead using 'Exporter' in B.pm and then 'use B;' in A.pm (also tried require)

I also tried using cgi app autorunmode in B.pm as well as in A.pm..

All give same error, any runmodes declared as "sub modename : Runmode {..}" which are not inside A.pm will stop compilation.

How do I get this to work... Please.. ? Any ideas?

update, here is an example..

In t/0.t:

use Test::Simple 'no_plan'; use lib './lib'; use A; my $a = new A; ok($a->run);

In lib/A.pm:

package A; use base 'CGI::Application'; use base 'B'; use CGI::Application::Plugin::AutoRunmode; use constant DEBUG => 0; use strict; sub setup { my $self = shift; $self->start_mode('importme'); $self->mode_param('rm'); } sub cgiapp_prerun { my $self = shift; print STDERR "I am prerun\n" if DEBUG; # This is needed to use a cgiapp_prerun witth AutoRunmode plugin CGI::Application::Plugin::AutoRunmode::cgiapp_prerun($self); } sub hithere : Runmode { my $self = shift; my $out = 'hi, there..'; return $out; } 1;

In B.pm:

package B; use CGI::Application::Plugin::AutoRunmode; sub importme : Runmode { my $self = shift; $self->header_type('redirect'); $self->header_props(-url=>'?rm=hithere'); return 'Redirecting..'; } 1;

I still get

xoot@moonshine temp# perl t/0.t
Invalid CODE attribute: Runmode at lib/B.pm line 4
BEGIN failed--compilation aborted at lib/B.pm line 9.
Compilation failed in require at (eval 4) line 3.
        ...propagated at /usr/lib/perl5/5.8.8/base.pm line 85.
BEGIN failed--compilation aborted at lib/A.pm line 4.
Compilation failed in require at t/0.t line 3.
BEGIN failed--compilation aborted at t/0.t line 3.
# Looks like your test died before it could output anything.
xoot@moonshine temp#

update I have realized now what was wrong. You must use base CGI::Application in the module you are importing!!

A.pm

use base 'CGI::Application'; use CGI::Application::Plugin::AutoRunmode; use base 'B';

B.pm

use base 'CGI::Application'; use CGI::Application::Plugin::AutoRunmode; sub useme : Runmode {}

Now, you can use runmodes in B.pm inside A.pm.


In reply to CGI::Application::Plugin::AutoRunmode importing runmodes problem by leocharre

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.