App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Chords/Parser.pm view on Meta::CPAN
$self->{format} = "";
}
else {
$self->{format} = $fmt;
}
return $self;
}
sub chord_display ( $self, $default = undef ) {
$self->{format};
}
sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
sub transcode ( $self, $dummy1, $dummy2=0 ) { $self }
sub canonical ( $self ) {
my $res = $self->{text};
return $res;
}
# For convenience.
sub is_chord ( $self ) { 0 };
sub is_annotation ( $self ) { 1 };
sub is_nc ( $self ) { 1 };
sub is_xpxc ( $self ) { 0 };
sub has_diagram ( $self ) { 0 };
sub is_gridstrum ( $self ) { 1 };
################ Chord objects: NC ################
package ChordPro::Chord::NC;
use String::Interpolate::Named;
our @ISA = 'ChordPro::Chord::Base';
sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
sub transcode ( $self, $dummy1, $dummy2=0 ) { $self }
sub canonical ( $self ) {
my $res = $self->{name};
return $res;
}
sub chord_display ( $self ) {
return interpolate( { args => $self }, $self->{name} );
}
# For convenience.
sub is_nc ( $self ) { 1 };
sub is_chord ( $self ) { 0 };
sub is_annotation ( $self ) { 0 };
sub has_diagram ( $self ) { 0 };
################ Testing ################
package main;
unless ( caller ) {
select(STDERR);
binmode(STDERR, ':utf8');
$::config = { settings => { chordnames => "strict" } };
$::options = { verbose => 2 };
foreach ( @ARGV ) {
if ( $_ eq '-' ) {
$::config = { settings => { chordnames => "relaxed" } };
ChordPro::Chords::Parser->reset_parsers("common");
next;
}
my $p0 = ChordPro::Chords::Parser->default;
my $p1 = ChordPro::Chords::Parser->get_parser("common", 1);
die unless $p0 eq $p1;
my $p2 = ChordPro::Chords::Parser->get_parser("nashville", 1);
my $p3 = ChordPro::Chords::Parser->get_parser("roman", 1);
my $info = $p1->parse($_);
$info = $p2->parse($_) if !$info && $p2;
$info = $p3->parse($_) if !$info && $p3;
print( "$_ => OOPS\n" ), next unless $info;
print( "$_ ($info->{system}) =>" );
print( " ", $info->transcode($_)->canonical, " ($_)" )
for qw( common nashville roman );
print( " '", $info->agnostic, "' (agnostic)\n" );
print( "$_ =>" );
print( " ", $info->transpose(ChordPro::Chords::Transpose::parse_transpose($_))->canonical, " ($_)" ) for -2..2;
print( "\n" );
# my $clone = $info->clone;
# delete($clone->{parser});
# print( ::dump($clone), "\n" );
}
}
1;
( run in 1.440 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )