App-ZofCMS

 view release on metacpan or  search on metacpan

lib/App/ZofCMS/Plugin/GoogleTime.pm  view on Meta::CPAN

        my ( $t, $q, $config ) = @_;
        return {
            location => 'Toronto',
        }
    },

B<Mandatory>. Takes either a hashref or a subref as a value. If subref is specified,
its return value will be assigned to C<plug_google_time> as if it was already there. If sub
returns
an C<undef>, then plugin will stop further processing. The C<@_> of the subref will
contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and
L<App::ZofCMS::Config> object. Possible keys/values for the hashref
are as follows:

=head3 C<location>

    plug_google_time => {
        location => 'Toronto',
    }

    plug_google_time => {
        location => [
            'Toronto',
            'New York',
        ],
    }

    plug_google_time => {
        location => sub {
            my ( $t, $q, $config ) = @_;
            return 'Toronto';
        },
    }

B<Mandatory>. Specifies location(s) for which you wish to obtain times.
The value can be either a direct string, an arrayref or a subref.
When value is a subref, its C<@_> will contain
(in that order): ZofCMS Template hashref, query parameters hashref and L<App::ZofCMS::Config>
object. The return value of the sub will be assigned to C<location> argument
as if it was already there.

The single string vs. arrayref values affect the output format (see section below).

=head3 C<ua>

    plug_google_time => {
        ua => LWP::UserAgent->new(
            agent    => "Opera 9.5",
            timeout  => 30,
        ),
    },

B<Optional>. Takes an L<LWP::UserAgent> object as a value; this object will be used for
accessing Google. B<Defaults to:>

    LWP::UserAgent->new(
        agent    => "Opera 9.5",
        timeout  => 30,
    ),

=head1 PLUGIN'S OUTPUT

    # location argument set to a string
    <tmpl_if name='plug_google_time_error'>
        <p class="error">Got error: <tmpl_var escape='html' name='plug_google_time_error'></p>
    <tmpl_else>
        <p>Time: <tmpl_var escape='html' name='plug_google_time'></p>
    </tmpl_if>


    # location argument set to an arrayref
    <ul>
        <tmpl_loop name='plug_google_time'>
        <li>
            <tmpl_if name='error'>
                Got error: <tmpl_var escape='html' name='error'>
            <tmpl_else>
                Time: <tmpl_var escape='html' name='time'>
            </tmpl_if>
        </li>
        </tmpl_loop>
    </ul>

Plugin will set C<< $t->{t}{plug_google_time} >> (where C<$t> is ZofCMS Template
hashref) to either a string or an
arrayref when C<location> plugin's argument is set to a string or arrayref respectively. Thus,
for arrayref values you'd use a C<< <tmpl_loop> >> plugins will use three variables
inside that loop: C<error>, C<time> and C<hash>; the C<error> variable will be present when
an error occured during title fetching. The C<time> will be the formated string of the
time including the location. The C<hash> variable will contain a hashref that is the
output of C<data()> method of L<WWW::Google::Time> module. Order
for arrayrefs will be the same as the order in C<location> argument.

If C<location> argument was set to a single string, then C<{plug_google_time}> will contain
the formated time of the location, C<{plug_google_time_error}> will be set if an error
occured and C<{plug_google_time_hash}> will contain the
output of C<data()> method of L<WWW::Google::Time> module.

=head1 REPOSITORY

Fork this module on GitHub:
L<https://github.com/zoffixznet/App-ZofCMS>

=head1 BUGS

To report bugs or request features, please use
L<https://github.com/zoffixznet/App-ZofCMS/issues>

If you can't access GitHub, you can email your request
to C<bug-App-ZofCMS at rt.cpan.org>

=head1 AUTHOR

Zoffix Znet <zoffix at cpan.org>
(L<http://zoffix.com/>, L<http://haslayout.net/>)

=head1 LICENSE

You can use and distribute this module under the same terms as Perl itself.
See the C<LICENSE> file included in this distribution for complete
details.



( run in 2.428 seconds using v1.01-cache-2.11-cpan-5623c5533a1 )