Cocoa-BatteryInfo

 view release on metacpan or  search on metacpan

lib/Cocoa/BatteryInfo.pm  view on Meta::CPAN

=head1 CLASS METHODS

=head2 info($source_name : Str)

    my $info = Cocoa::BatteryInfo->info;
    # or
    my $info = Cocoa::BatteryInfo->info($source_name);

Returns readable information about the specific power source.

If C<$source_name> is not set, returns first source information.
If system doesn't have any battery, returns nothing.

=head2 sources()

    my @sources = Cocoa::BatteryInfo->sources;

Returns list of power sources that connected to current machine.

=head2 time_remaining_estimate()

    my $sec = Cocoa::BatteryInfo->time_remaining_estimate;

Returns 'unknown' if the OS cannot determine the time remaining.
Returns 'unlimited' if the system has an unlimited power source.

Otherwise returns estimated time remaining until all power sources are empty (in seconds).

=head2 battery_warning_level()

    my $level = Cocoa::BatteryInfo->battery_warning_level;

Indicates whether the system is at a low battery warning level.

C<$level> is one of following levels:

=over 4

=item * Cocoa::BatteryInfo::LowBatteryWarningNone (== 1) (No battery warnings)

=item * Cocoa::BatteryInfo::LowBatteryWarningEarly (== 2) (Early battery warnings)

=item * Cocoa::BatteryInfo::LowBatteryWarningFinal (== 3) (Final battery warnings)

=back

=head1 CALLBACKS

=head2 low_battery_handler($callback :CodeRef)

Register low battery event handler called when the battery time remaining drops into a warnable level.

=head2 time_remaining_handler($callback :CodeRef)

Register time remaining event handler called when the power source(s) time remaining changes.

=head1 NOTICE

Callbacks listed above do nothing without under the Cocoa's event loop.

To work those callbacks correctly, you have to use this module with L<Cocoa::EventLoop>:

    use Cocoa::EventLoop;
    use Cocoa::BatteryInfo;
    
    Cocoa::BatteryInfo::low_battery_handler {
        # do something;
    };
    
    Cocoa::EventLoop->run;

=head1 AUTHOR

Daisuke Murase <typester@cpan.org>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2012 Daisuke Murase. All rights reserved.

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

The full text of the license can be found in the
LICENSE file included with this module.

=cut



( run in 0.529 second using v1.01-cache-2.11-cpan-5a3173703d6 )