Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

You seem to be hard-coding information about a specific battery into the battery class.

That would be like if I was trying to create a class to represent people, hard-coding my personal details as the defaults.

use 5.010; { package Acpi::Info; use Moose; my @attrs = qw< name type online status present technology voltage_min_design voltage_now current_now charge_full_design charge_full charge_now model_name manufacturer serial_number >; for my $attr (@attrs) { has $attr => ( is => "ro", lazy => 1, default => sub { my $self = shift; $self->_build($attr) } ); } sub _build { my ($self, $key) = @_; my $data = $self->_data; $key = "POWER_SUPPLY_" . uc($key); $data =~ /^$key=(.+?)$/m and $1; } has file => ( is => "ro", isa => "Str", ); has _data => ( is => "ro", isa => "Str", lazy => 1, builder => '_build_data', ); sub _build_data { my $self = shift; local @ARGV = $self->file; local $/ = <ARGV>; } } # Usage # my $i1 = Acpi::Info->new(file => '/sys/class/power_supply/BAT1/uevent' +); my $i2 = Acpi::Info->new(file => '/sys/class/power_supply/ACAD/uevent' +); for my $supply ($i1, $i2) { say "----"; for my $attr ($supply->meta->get_all_attributes) { my $aname = $attr->name; next if $aname =~ /^_/; say $aname, " = ", $supply->$aname; } }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Moose: using value of one attribute in another attribute by tobyink
in thread Moose: using value of one attribute in another attribute by mimosinnet

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the voices are still...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (2)
    As of 2018-02-23 03:31 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (300 votes). Check out past polls.