On Wed, Jan 29, 2003 at 07:49:12AM +0000, Matt Sergeant wrote:
> Subclass the File provider if you're going to subclass anything - that 
> way the code to get the stylesheets should still do the right thing.

OK.  Real life intervened for a bit, but I'm back to working on this.

I have my subclass of the ::File provider.  It has to do one of two
things.

If there was a size parameter passed in the query string then scale a
JPG to that size, and then return it.  Alternatively, if there was no
size parameter then return some XML -- the Apache config file then
directs AxKit to style this appropriately.

My ::Provider code looks like this:

    package Apache::App::Gallery::Provider;

    # Lots of 'use' statements

    use base qw(Apache::AxKit::Provider::File);

    sub get_fh {
        my $self = shift;
        my $r    = $self->{apache};

        return $self->SUPER::get_fh()   # Only handle images
                unless substr($r->content_type(), 0, 6) eq 'image/';

        my $size = $r->param('size');

        # If no size parameter was passed in then we need to generate
        # the XML for the image's page.  That's done by get_strref(),
        # so bail out here
        if(! defined $size) {
            AxKit::Debug(5, "No 'size' parameter provided");
            throw Apache::AxKit::Exception::IO( -text => "No 'size' parameter 
provided");
        }

        # Do stuff to generate the image

        $r->filename($generated_image);
        return DECLINED;
    }

    sub get_strref {
        my $self = shift;
        my $r    = $self->{apache};

        return $self->SUPER::get_strref()       # Only handle images
             unless substr($r->content_type(), 0, 6) eq 'image/';

        # Generate some XML and return it
        my $xml = $self->generate_some_xml();

        return \$xml;
    }

    1;

get_fh() works exactly as expected.

get_strref() barfs.

It turns out that in get_strref() the content type is, for some reason,
set to C<changeme>.  If I comment out the check in get_strref() then
the XML is generated and styled by AxKit correctly.

Poking through the AxKit code I can see where the content type is set to
C<changeme>, and the original is stuck in C<$AxKit::OrigType>, so I
could extract it from there, but that doesn't seem terribly clean.

I'm also not convinced that I need to do the check in get_strref(),
since the check in get_fh() should cover things, but I'm erring on the
cautious side at the moment while I write this.

Is this a bug in AxKit, or a misunderstanding on my part?  I'm using a
CVS snapshot from a couple of weeks before 1.6.1 was released at the
moment.

N
-- 
C.R.F. Consulting ltd                                W: 01895 466 766
                                                     M: 07973 840 839

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to