
WWW::Mixi::OO::Page - WWW::Mixi::OO's Pages base class

package WWW::Mixi::OO::Foo;
use base qw(WWW::Mixi::OO::Page);
sub uri {
shift->absolute_uri('foo.pl');
}
# some implementations...

pages base class.

# subclass
sub new {
my $this = shift->SUPER::new(@_);
# some initializations...
}
# call
my $page = $pkg->new($session);
constructor of page. please override if you need some initializations.
# subclass
sub uri {
my ($this, %options) = @_;
$this->SUPER::uri(_path => 'foo',
_params => {
a => b,
},
%options);
}
# call
my $uri = $page->uri([opt => val], ...);
return URI of page.
# subclass
sub parse_uri {
my ($this, $data, %options) = @_;
$this->copy_hash_val($data->{params}, \%options, 'page');
if ($data->{path} eq "show_friend") {
# blah...
}
if ($data->{uri}->...) {
# maybe you won't use this
}
$this->SUPER::uri($data, %options);
}
# call
my %options = $page->analyze_uri($uri);
return page information of URI.
# subclass
sub parse {
my ($this, %options) = @_;
# parse...
my $part = $this->parse_extract_parts(qw/.../);
return () unless defined $part;
# return
return ({ a => b, c => d }, { a => e, c => f }, ...);
}
# call
my @datas = $page->parse;
page parser. please return hashref array.
my $data = $page->parse_banner;
parse banner. structure:
link: link to ad page. subject: subject of ad(banner's alt text). image: image of banner height: height of image width: width of image
my @data = $page->parse_mainmenu;
parse mainmenu. structure:
link: link to page subject: subject of page
my @data = $page->parse_tool_bar;
parse toolbar. structure:
link: link to page subject: subject of page image: image of toolbar. height: height of image width: width of image
$page->get([opt => val], ...);
handy method. call ->set_content and ->parse.
$page->set_content($uri);
or
$page->set_content(%options);
set content to specified by uri or options.

methods to useful for subclass implementations
# array my @parts = $this->parse_extract_parts(qr|....|); return () unless @parts; # more parse with @parts
or
# scalar my $part = $this->parse_extract_parts(qr|....|); return () unless defined $part; # more parse with $part
extract part(s) from current content.
$page->html_attr_to_uri('src', 'src="foobar" ...');
parse html attrs string(->html_attrs_to_hash) and extract attr(->generate_ignore_case_hash()->{$attrname}) and resolve to absolute URI(->absolute_linked_uri).
$page->html_anchor_to_uri("href='...'...");
handy method. call ->html_attr_to_uri with 'href'.
my $cache = $pkg->cache;
if (defined $cache->{foo}) {
return $cache->{foo};
}
...
get modules's cache storage.
# from subclass
__PACKAGE__->mk_cached_parser(qw(foo bar));
sub _parse_foo {
# ...
return $foo; # please return scalar value.
}
generate cached parser (proxy) method. use _parse_(name) to real parser method.
# from subclass __PACKAGE__->mk_get_method(qw(foo bar));
generate get handy method.

parent WWW::Mixi::OO object.


for listed content: WWW::Mixi::OO::ListPage

Topia <topia@clovery.jp>

Copyright (C) 2005 by Topia.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.