Dist-Zilla-Plugin-LogContextual

 view release on metacpan or  search on metacpan

lib/Dist/Zilla/Plugin/LogContextual.pm  view on Meta::CPAN

    use Moose;
    use Log::Contextual::LogDispatchouli  qw( log_debug );
    with 'Dist::Zilla::Role::Plugin';

    sub foo {
        log_debug {  }; # messes up and tries to call the log_debug method provided by $self->logger
    }

There's an easy way around this, but it doesn't seem obvious at first glance.

    use Moose;
    use Log::Contextual::LogDispatchouli qw( log_debug );
    use namespace::autoclean;
    with 'Dist::Zilla::Role::Plugin';

    sub foo {
        log_debug {  }; # Now works
    }

If you're confused, that is quite o.k.

But its sensible once you understand how.

Essentially, because the C<log_debug> C<sub> is removed at compile time, all calls to that become fixed, instead of flexible.

So here's how C<perl> processes the above code:

    # COMPILE PHASE
    use Moose;
    use Log::Contextual::LogDispatchouli qw( log_debug );
    use namespace::autoclean;

    sub foo {
        log_debug {  }; # BINDS this call to the imported sub
    }

    # END OF COMPILE PHASE
    # namespace::autoclean removes *log_debug forcing the bind
    # RUNTIME
    with  'Dist::Zilla::Role::Plugin'; # Cant change compile-time things.

Its not 100% ideal, but it works!.

=head1 CAVEATS

=over 4

=item * B<NO PREFIXES>

At this time, The nice pretty C<[Foo/Bar]> prefix from C<< $plugin->plugin_name >> is not supported.

We're not sure if it ever will, it probably will, but the code makes my head hurt at present.

Was better to release something, albeit feature incomplete, than to release nothing at all.

=item * B<< REQUIRES C<::LogDispatchouli> >> subclass

This seems in contrast to the Log::Contextual design principles, things invoking
loggers shouldn't care about how they're working, just they should work.

I'm I<Hoping> in a future release of C<::LogDispatchouli> that it can transparently
do the right thing when calling code simply does

    use Log::Contextual

So the C<Dispatchouli> is I<strictly> top level knowledge.

But I'll wait for updates on how that should work before I make it work that way =)

=back

=head1 AUTHOR

Kent Fredric <kentfredric@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Kent Fredric <kentfredric@gmail.com>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.911 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )